TrashbinHome.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /** @var CalDavBackend */
  24. private $caldavBackend;
  25. /** @var array */
  26. private $principalInfo;
  27. public function __construct(CalDavBackend $caldavBackend,
  28. array $principalInfo) {
  29. $this->caldavBackend = $caldavBackend;
  30. $this->principalInfo = $principalInfo;
  31. }
  32. public function getOwner(): string {
  33. return $this->principalInfo['uri'];
  34. }
  35. public function createFile($name, $data = null) {
  36. throw new Forbidden('Permission denied to create files in the trashbin');
  37. }
  38. public function createDirectory($name) {
  39. throw new Forbidden('Permission denied to create a directory in the trashbin');
  40. }
  41. public function getChild($name): INode {
  42. switch ($name) {
  43. case RestoreTarget::NAME:
  44. return new RestoreTarget();
  45. case DeletedCalendarObjectsCollection::NAME:
  46. return new DeletedCalendarObjectsCollection(
  47. $this->caldavBackend,
  48. $this->principalInfo
  49. );
  50. }
  51. throw new NotFound();
  52. }
  53. public function getChildren(): array {
  54. return [
  55. new RestoreTarget(),
  56. new DeletedCalendarObjectsCollection(
  57. $this->caldavBackend,
  58. $this->principalInfo
  59. ),
  60. ];
  61. }
  62. public function childExists($name): bool {
  63. return in_array($name, [
  64. RestoreTarget::NAME,
  65. DeletedCalendarObjectsCollection::NAME,
  66. ], true);
  67. }
  68. public function delete() {
  69. throw new Forbidden('Permission denied to delete the trashbin');
  70. }
  71. public function getName(): string {
  72. return self::NAME;
  73. }
  74. public function setName($name) {
  75. throw new Forbidden('Permission denied to rename the trashbin');
  76. }
  77. public function getLastModified(): int {
  78. return 0;
  79. }
  80. public function propPatch(PropPatch $propPatch): void {
  81. throw new Forbidden('not implemented');
  82. }
  83. public function getProperties($properties): array {
  84. return [
  85. '{DAV:}resourcetype' => new ResourceType([
  86. '{DAV:}collection',
  87. sprintf('{%s}trash-bin', \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD),
  88. ]),
  89. ];
  90. }
  91. }