1
0

TrashHome.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\IUser;
  10. use Sabre\DAV\Exception\Forbidden;
  11. use Sabre\DAV\Exception\NotFound;
  12. use Sabre\DAV\ICollection;
  13. class TrashHome implements ICollection {
  14. public function __construct(
  15. private array $principalInfo,
  16. private ITrashManager $trashManager,
  17. private IUser $user,
  18. ) {
  19. }
  20. public function delete() {
  21. throw new Forbidden();
  22. }
  23. public function getName(): string {
  24. [, $name] = \Sabre\Uri\split($this->principalInfo['uri']);
  25. return $name;
  26. }
  27. public function setName($name) {
  28. throw new Forbidden('Permission denied to rename this trashbin');
  29. }
  30. public function createFile($name, $data = null) {
  31. throw new Forbidden('Not allowed to create files in the trashbin');
  32. }
  33. public function createDirectory($name) {
  34. throw new Forbidden('Not allowed to create folders in the trashbin');
  35. }
  36. public function getChild($name) {
  37. if ($name === 'restore') {
  38. return new RestoreFolder();
  39. }
  40. if ($name === 'trash') {
  41. return new TrashRoot($this->user, $this->trashManager);
  42. }
  43. throw new NotFound();
  44. }
  45. public function getChildren(): array {
  46. return [
  47. new RestoreFolder(),
  48. new TrashRoot($this->user, $this->trashManager)
  49. ];
  50. }
  51. public function childExists($name): bool {
  52. return $name === 'restore' || $name === 'trash';
  53. }
  54. public function getLastModified(): int {
  55. return 0;
  56. }
  57. }