You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VersionHome.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_Versions\Sabre;
  25. use OC\User\NoUserException;
  26. use OCA\Files_Versions\Versions\IVersionManager;
  27. use OCP\Files\IRootFolder;
  28. use OCP\IUserManager;
  29. use Sabre\DAV\Exception\Forbidden;
  30. use Sabre\DAV\ICollection;
  31. class VersionHome implements ICollection {
  32. /** @var array */
  33. private $principalInfo;
  34. /** @var IRootFolder */
  35. private $rootFolder;
  36. /** @var IUserManager */
  37. private $userManager;
  38. /** @var IVersionManager */
  39. private $versionManager;
  40. public function __construct(array $principalInfo, IRootFolder $rootFolder, IUserManager $userManager, IVersionManager $versionManager) {
  41. $this->principalInfo = $principalInfo;
  42. $this->rootFolder = $rootFolder;
  43. $this->userManager = $userManager;
  44. $this->versionManager = $versionManager;
  45. }
  46. private function getUser() {
  47. [, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
  48. $user = $this->userManager->get($name);
  49. if (!$user) {
  50. throw new NoUserException();
  51. }
  52. return $user;
  53. }
  54. public function delete() {
  55. throw new Forbidden();
  56. }
  57. public function getName(): string {
  58. return $this->getUser()->getUID();
  59. }
  60. public function setName($name) {
  61. throw new Forbidden();
  62. }
  63. public function createFile($name, $data = null) {
  64. throw new Forbidden();
  65. }
  66. public function createDirectory($name) {
  67. throw new Forbidden();
  68. }
  69. public function getChild($name) {
  70. $user = $this->getUser();
  71. if ($name === 'versions') {
  72. return new VersionRoot($user, $this->rootFolder, $this->versionManager);
  73. }
  74. if ($name === 'restore') {
  75. return new RestoreFolder();
  76. }
  77. }
  78. public function getChildren() {
  79. $user = $this->getUser();
  80. return [
  81. new VersionRoot($user, $this->rootFolder, $this->versionManager),
  82. new RestoreFolder(),
  83. ];
  84. }
  85. public function childExists($name) {
  86. return $name === 'versions' || $name === 'restore';
  87. }
  88. public function getLastModified() {
  89. return 0;
  90. }
  91. }