TrashbinHome.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\DAV\CalDAV\Trashbin;
  25. use OCA\DAV\CalDAV\CalDavBackend;
  26. use Sabre\DAV\Exception\Forbidden;
  27. use Sabre\DAV\Exception\NotFound;
  28. use Sabre\DAV\ICollection;
  29. use Sabre\DAV\INode;
  30. use Sabre\DAV\IProperties;
  31. use Sabre\DAV\PropPatch;
  32. use Sabre\DAV\Xml\Property\ResourceType;
  33. use Sabre\DAVACL\ACLTrait;
  34. use Sabre\DAVACL\IACL;
  35. use function in_array;
  36. use function sprintf;
  37. class TrashbinHome implements IACL, ICollection, IProperties {
  38. use ACLTrait;
  39. public const NAME = 'trashbin';
  40. /** @var CalDavBackend */
  41. private $caldavBackend;
  42. /** @var array */
  43. private $principalInfo;
  44. public function __construct(CalDavBackend $caldavBackend,
  45. array $principalInfo) {
  46. $this->caldavBackend = $caldavBackend;
  47. $this->principalInfo = $principalInfo;
  48. }
  49. public function getOwner(): string {
  50. return $this->principalInfo['uri'];
  51. }
  52. public function createFile($name, $data = null) {
  53. throw new Forbidden('Permission denied to create files in the trashbin');
  54. }
  55. public function createDirectory($name) {
  56. throw new Forbidden('Permission denied to create a directory in the trashbin');
  57. }
  58. public function getChild($name): INode {
  59. switch ($name) {
  60. case RestoreTarget::NAME:
  61. return new RestoreTarget();
  62. case DeletedCalendarObjectsCollection::NAME:
  63. return new DeletedCalendarObjectsCollection(
  64. $this->caldavBackend,
  65. $this->principalInfo
  66. );
  67. }
  68. throw new NotFound();
  69. }
  70. public function getChildren(): array {
  71. return [
  72. new RestoreTarget(),
  73. new DeletedCalendarObjectsCollection(
  74. $this->caldavBackend,
  75. $this->principalInfo
  76. ),
  77. ];
  78. }
  79. public function childExists($name): bool {
  80. return in_array($name, [
  81. RestoreTarget::NAME,
  82. DeletedCalendarObjectsCollection::NAME,
  83. ], true);
  84. }
  85. public function delete() {
  86. throw new Forbidden('Permission denied to delete the trashbin');
  87. }
  88. public function getName(): string {
  89. return self::NAME;
  90. }
  91. public function setName($name) {
  92. throw new Forbidden('Permission denied to rename the trashbin');
  93. }
  94. public function getLastModified(): int {
  95. return 0;
  96. }
  97. public function propPatch(PropPatch $propPatch): void {
  98. throw new Forbidden('not implemented');
  99. }
  100. public function getProperties($properties): array {
  101. return [
  102. '{DAV:}resourcetype' => new ResourceType([
  103. '{DAV:}collection',
  104. sprintf('{%s}trash-bin', \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD),
  105. ]),
  106. ];
  107. }
  108. }