DeletedCalendarObject.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 OCA\DAV\CalDAV\IRestorable;
  27. use Sabre\CalDAV\ICalendarObject;
  28. use Sabre\DAV\Exception\Forbidden;
  29. use Sabre\DAVACL\ACLTrait;
  30. use Sabre\DAVACL\IACL;
  31. class DeletedCalendarObject implements IACL, ICalendarObject, IRestorable {
  32. use ACLTrait;
  33. /** @var string */
  34. private $name;
  35. /** @var mixed[] */
  36. private $objectData;
  37. /** @var string */
  38. private $principalUri;
  39. /** @var CalDavBackend */
  40. private $calDavBackend;
  41. public function __construct(string $name,
  42. array $objectData,
  43. string $principalUri,
  44. CalDavBackend $calDavBackend) {
  45. $this->name = $name;
  46. $this->objectData = $objectData;
  47. $this->calDavBackend = $calDavBackend;
  48. $this->principalUri = $principalUri;
  49. }
  50. public function delete() {
  51. $this->calDavBackend->deleteCalendarObject(
  52. $this->objectData['calendarid'],
  53. $this->objectData['uri'],
  54. CalDavBackend::CALENDAR_TYPE_CALENDAR,
  55. true
  56. );
  57. }
  58. public function getName() {
  59. return $this->name;
  60. }
  61. public function setName($name) {
  62. throw new Forbidden();
  63. }
  64. public function getLastModified() {
  65. return 0;
  66. }
  67. public function put($data) {
  68. throw new Forbidden();
  69. }
  70. public function get() {
  71. return $this->objectData['calendardata'];
  72. }
  73. public function getContentType() {
  74. $mime = 'text/calendar; charset=utf-8';
  75. if (isset($this->objectData['component']) && $this->objectData['component']) {
  76. $mime .= '; component='.$this->objectData['component'];
  77. }
  78. return $mime;
  79. }
  80. public function getETag() {
  81. return $this->objectData['etag'];
  82. }
  83. public function getSize() {
  84. return (int) $this->objectData['size'];
  85. }
  86. public function restore(): void {
  87. $this->calDavBackend->restoreCalendarObject($this->objectData);
  88. }
  89. public function getDeletedAt(): ?int {
  90. return $this->objectData['deleted_at'] ? (int) $this->objectData['deleted_at'] : null;
  91. }
  92. public function getCalendarUri(): string {
  93. return $this->objectData['calendaruri'];
  94. }
  95. public function getACL(): array {
  96. return [
  97. [
  98. 'privilege' => '{DAV:}read', // For queries
  99. 'principal' => $this->getOwner(),
  100. 'protected' => true,
  101. ],
  102. [
  103. 'privilege' => '{DAV:}unbind', // For moving and deletion
  104. 'principal' => '{DAV:}owner',
  105. 'protected' => true,
  106. ],
  107. ];
  108. }
  109. public function getOwner() {
  110. return $this->principalUri;
  111. }
  112. }