RootCollection.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
  5. *
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\Files_Trashbin\Sabre;
  26. use OCA\Files_Trashbin\Trash\ITrashManager;
  27. use OCP\IConfig;
  28. use Sabre\DAV\INode;
  29. use Sabre\DAVACL\AbstractPrincipalCollection;
  30. use Sabre\DAVACL\PrincipalBackend;
  31. class RootCollection extends AbstractPrincipalCollection {
  32. /** @var ITrashManager */
  33. private $trashManager;
  34. public function __construct(
  35. ITrashManager $trashManager,
  36. PrincipalBackend\BackendInterface $principalBackend,
  37. IConfig $config
  38. ) {
  39. parent::__construct($principalBackend, 'principals/users');
  40. $this->trashManager = $trashManager;
  41. $this->disableListing = !$config->getSystemValue('debug', false);
  42. }
  43. /**
  44. * This method returns a node for a principal.
  45. *
  46. * The passed array contains principal information, and is guaranteed to
  47. * at least contain a uri item. Other properties may or may not be
  48. * supplied by the authentication backend.
  49. *
  50. * @param array $principalInfo
  51. * @return INode
  52. */
  53. public function getChildForPrincipal(array $principalInfo): TrashHome {
  54. [, $name] = \Sabre\Uri\split($principalInfo['uri']);
  55. $user = \OC::$server->getUserSession()->getUser();
  56. if (is_null($user) || $name !== $user->getUID()) {
  57. throw new \Sabre\DAV\Exception\Forbidden();
  58. }
  59. return new TrashHome($principalInfo, $this->trashManager, $user);
  60. }
  61. public function getName(): string {
  62. return 'trashbin';
  63. }
  64. }