VersionHome.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Files_Versions\Sabre;
  7. use OC\User\NoUserException;
  8. use OCA\Files_Versions\Versions\IVersionManager;
  9. use OCP\Files\IRootFolder;
  10. use OCP\IUserManager;
  11. use Sabre\DAV\Exception\Forbidden;
  12. use Sabre\DAV\ICollection;
  13. class VersionHome implements ICollection {
  14. public function __construct(
  15. private array $principalInfo,
  16. private IRootFolder $rootFolder,
  17. private IUserManager $userManager,
  18. private IVersionManager $versionManager,
  19. ) {
  20. }
  21. private function getUser() {
  22. [, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
  23. $user = $this->userManager->get($name);
  24. if (!$user) {
  25. throw new NoUserException();
  26. }
  27. return $user;
  28. }
  29. public function delete() {
  30. throw new Forbidden();
  31. }
  32. public function getName(): string {
  33. return $this->getUser()->getUID();
  34. }
  35. public function setName($name) {
  36. throw new Forbidden();
  37. }
  38. public function createFile($name, $data = null) {
  39. throw new Forbidden();
  40. }
  41. public function createDirectory($name) {
  42. throw new Forbidden();
  43. }
  44. public function getChild($name) {
  45. $user = $this->getUser();
  46. if ($name === 'versions') {
  47. return new VersionRoot($user, $this->rootFolder, $this->versionManager);
  48. }
  49. if ($name === 'restore') {
  50. return new RestoreFolder();
  51. }
  52. }
  53. public function getChildren() {
  54. $user = $this->getUser();
  55. return [
  56. new VersionRoot($user, $this->rootFolder, $this->versionManager),
  57. new RestoreFolder(),
  58. ];
  59. }
  60. public function childExists($name) {
  61. return $name === 'versions' || $name === 'restore';
  62. }
  63. public function getLastModified() {
  64. return 0;
  65. }
  66. }