1
0

TrashbinHome.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV\Trashbin;
  8. use OCA\DAV\CalDAV\CalDavBackend;
  9. use Sabre\DAV\Exception\Forbidden;
  10. use Sabre\DAV\Exception\NotFound;
  11. use Sabre\DAV\ICollection;
  12. use Sabre\DAV\INode;
  13. use Sabre\DAV\IProperties;
  14. use Sabre\DAV\PropPatch;
  15. use Sabre\DAV\Xml\Property\ResourceType;
  16. use Sabre\DAVACL\ACLTrait;
  17. use Sabre\DAVACL\IACL;
  18. use function in_array;
  19. use function sprintf;
  20. class TrashbinHome implements IACL, ICollection, IProperties {
  21. use ACLTrait;
  22. public const NAME = 'trashbin';
  23. public function __construct(
  24. private CalDavBackend $caldavBackend,
  25. private array $principalInfo,
  26. ) {
  27. }
  28. public function getOwner(): string {
  29. return $this->principalInfo['uri'];
  30. }
  31. public function createFile($name, $data = null) {
  32. throw new Forbidden('Permission denied to create files in the trashbin');
  33. }
  34. public function createDirectory($name) {
  35. throw new Forbidden('Permission denied to create a directory in the trashbin');
  36. }
  37. public function getChild($name): INode {
  38. switch ($name) {
  39. case RestoreTarget::NAME:
  40. return new RestoreTarget();
  41. case DeletedCalendarObjectsCollection::NAME:
  42. return new DeletedCalendarObjectsCollection(
  43. $this->caldavBackend,
  44. $this->principalInfo
  45. );
  46. }
  47. throw new NotFound();
  48. }
  49. public function getChildren(): array {
  50. return [
  51. new RestoreTarget(),
  52. new DeletedCalendarObjectsCollection(
  53. $this->caldavBackend,
  54. $this->principalInfo
  55. ),
  56. ];
  57. }
  58. public function childExists($name): bool {
  59. return in_array($name, [
  60. RestoreTarget::NAME,
  61. DeletedCalendarObjectsCollection::NAME,
  62. ], true);
  63. }
  64. public function delete() {
  65. throw new Forbidden('Permission denied to delete the trashbin');
  66. }
  67. public function getName(): string {
  68. return self::NAME;
  69. }
  70. public function setName($name) {
  71. throw new Forbidden('Permission denied to rename the trashbin');
  72. }
  73. public function getLastModified(): int {
  74. return 0;
  75. }
  76. public function propPatch(PropPatch $propPatch): void {
  77. throw new Forbidden('not implemented');
  78. }
  79. public function getProperties($properties): array {
  80. return [
  81. '{DAV:}resourcetype' => new ResourceType([
  82. '{DAV:}collection',
  83. sprintf('{%s}trash-bin', \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD),
  84. ]),
  85. ];
  86. }
  87. }