1
0

VersionHome.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. /** @var array */
  15. private $principalInfo;
  16. /** @var IRootFolder */
  17. private $rootFolder;
  18. /** @var IUserManager */
  19. private $userManager;
  20. /** @var IVersionManager */
  21. private $versionManager;
  22. public function __construct(array $principalInfo, IRootFolder $rootFolder, IUserManager $userManager, IVersionManager $versionManager) {
  23. $this->principalInfo = $principalInfo;
  24. $this->rootFolder = $rootFolder;
  25. $this->userManager = $userManager;
  26. $this->versionManager = $versionManager;
  27. }
  28. private function getUser() {
  29. [, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
  30. $user = $this->userManager->get($name);
  31. if (!$user) {
  32. throw new NoUserException();
  33. }
  34. return $user;
  35. }
  36. public function delete() {
  37. throw new Forbidden();
  38. }
  39. public function getName(): string {
  40. return $this->getUser()->getUID();
  41. }
  42. public function setName($name) {
  43. throw new Forbidden();
  44. }
  45. public function createFile($name, $data = null) {
  46. throw new Forbidden();
  47. }
  48. public function createDirectory($name) {
  49. throw new Forbidden();
  50. }
  51. public function getChild($name) {
  52. $user = $this->getUser();
  53. if ($name === 'versions') {
  54. return new VersionRoot($user, $this->rootFolder, $this->versionManager);
  55. }
  56. if ($name === 'restore') {
  57. return new RestoreFolder();
  58. }
  59. }
  60. public function getChildren() {
  61. $user = $this->getUser();
  62. return [
  63. new VersionRoot($user, $this->rootFolder, $this->versionManager),
  64. new RestoreFolder(),
  65. ];
  66. }
  67. public function childExists($name) {
  68. return $name === 'versions' || $name === 'restore';
  69. }
  70. public function getLastModified() {
  71. return 0;
  72. }
  73. }