1
0

RootCollection.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Trashbin\Sabre;
  8. use OCA\Files_Trashbin\Trash\ITrashManager;
  9. use OCP\IConfig;
  10. use Sabre\DAV\INode;
  11. use Sabre\DAVACL\AbstractPrincipalCollection;
  12. use Sabre\DAVACL\PrincipalBackend;
  13. class RootCollection extends AbstractPrincipalCollection {
  14. /** @var ITrashManager */
  15. private $trashManager;
  16. public function __construct(
  17. ITrashManager $trashManager,
  18. PrincipalBackend\BackendInterface $principalBackend,
  19. IConfig $config
  20. ) {
  21. parent::__construct($principalBackend, 'principals/users');
  22. $this->trashManager = $trashManager;
  23. $this->disableListing = !$config->getSystemValue('debug', false);
  24. }
  25. /**
  26. * This method returns a node for a principal.
  27. *
  28. * The passed array contains principal information, and is guaranteed to
  29. * at least contain a uri item. Other properties may or may not be
  30. * supplied by the authentication backend.
  31. *
  32. * @param array $principalInfo
  33. * @return INode
  34. */
  35. public function getChildForPrincipal(array $principalInfo): TrashHome {
  36. [, $name] = \Sabre\Uri\split($principalInfo['uri']);
  37. $user = \OC::$server->getUserSession()->getUser();
  38. if (is_null($user) || $name !== $user->getUID()) {
  39. throw new \Sabre\DAV\Exception\Forbidden();
  40. }
  41. return new TrashHome($principalInfo, $this->trashManager, $user);
  42. }
  43. public function getName(): string {
  44. return 'trashbin';
  45. }
  46. }