RootCollection.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 OCA\Files_Versions\Versions\IVersionManager;
  8. use OCP\Files\IRootFolder;
  9. use OCP\IConfig;
  10. use OCP\IUserManager;
  11. use OCP\IUserSession;
  12. use Sabre\DAV\INode;
  13. use Sabre\DAVACL\AbstractPrincipalCollection;
  14. use Sabre\DAVACL\PrincipalBackend;
  15. class RootCollection extends AbstractPrincipalCollection {
  16. /** @var IRootFolder */
  17. private $rootFolder;
  18. /** @var IUserManager */
  19. private $userManager;
  20. /** @var IVersionManager */
  21. private $versionManager;
  22. /** @var IUserSession */
  23. private $userSession;
  24. public function __construct(
  25. PrincipalBackend\BackendInterface $principalBackend,
  26. IRootFolder $rootFolder,
  27. IConfig $config,
  28. IUserManager $userManager,
  29. IVersionManager $versionManager,
  30. IUserSession $userSession
  31. ) {
  32. parent::__construct($principalBackend, 'principals/users');
  33. $this->rootFolder = $rootFolder;
  34. $this->userManager = $userManager;
  35. $this->versionManager = $versionManager;
  36. $this->userSession = $userSession;
  37. $this->disableListing = !$config->getSystemValue('debug', false);
  38. }
  39. /**
  40. * This method returns a node for a principal.
  41. *
  42. * The passed array contains principal information, and is guaranteed to
  43. * at least contain a uri item. Other properties may or may not be
  44. * supplied by the authentication backend.
  45. *
  46. * @param array $principalInfo
  47. * @return INode
  48. */
  49. public function getChildForPrincipal(array $principalInfo) {
  50. [, $name] = \Sabre\Uri\split($principalInfo['uri']);
  51. $user = $this->userSession->getUser();
  52. if (is_null($user) || $name !== $user->getUID()) {
  53. throw new \Sabre\DAV\Exception\Forbidden();
  54. }
  55. return new VersionHome($principalInfo, $this->rootFolder, $this->userManager, $this->versionManager);
  56. }
  57. public function getName() {
  58. return 'versions';
  59. }
  60. }