1
0

TrashHome.php 1.7 KB

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