1
0

RootCollection.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public function __construct(
  17. PrincipalBackend\BackendInterface $principalBackend,
  18. private IRootFolder $rootFolder,
  19. IConfig $config,
  20. private IUserManager $userManager,
  21. private IVersionManager $versionManager,
  22. private IUserSession $userSession,
  23. ) {
  24. parent::__construct($principalBackend, 'principals/users');
  25. $this->disableListing = !$config->getSystemValue('debug', false);
  26. }
  27. /**
  28. * This method returns a node for a principal.
  29. *
  30. * The passed array contains principal information, and is guaranteed to
  31. * at least contain a uri item. Other properties may or may not be
  32. * supplied by the authentication backend.
  33. *
  34. * @param array $principalInfo
  35. * @return INode
  36. */
  37. public function getChildForPrincipal(array $principalInfo) {
  38. [, $name] = \Sabre\Uri\split($principalInfo['uri']);
  39. $user = $this->userSession->getUser();
  40. if (is_null($user) || $name !== $user->getUID()) {
  41. throw new \Sabre\DAV\Exception\Forbidden();
  42. }
  43. return new VersionHome($principalInfo, $this->rootFolder, $this->userManager, $this->versionManager);
  44. }
  45. public function getName() {
  46. return 'versions';
  47. }
  48. }