1
0

RootCollection.php 1.4 KB

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