You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CachedSubscription.php 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  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;
  25. use Sabre\CalDAV\Backend\BackendInterface;
  26. use Sabre\DAV\Exception\MethodNotAllowed;
  27. use Sabre\DAV\Exception\NotFound;
  28. use Sabre\DAV\PropPatch;
  29. /**
  30. * Class CachedSubscription
  31. *
  32. * @package OCA\DAV\CalDAV
  33. * @property BackendInterface|CalDavBackend $caldavBackend
  34. */
  35. class CachedSubscription extends \Sabre\CalDAV\Calendar {
  36. /**
  37. * @return string
  38. */
  39. public function getPrincipalURI():string {
  40. return $this->calendarInfo['principaluri'];
  41. }
  42. /**
  43. * @return array
  44. */
  45. public function getACL():array {
  46. return [
  47. [
  48. 'privilege' => '{DAV:}read',
  49. 'principal' => $this->getOwner(),
  50. 'protected' => true,
  51. ],
  52. [
  53. 'privilege' => '{DAV:}read',
  54. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  55. 'protected' => true,
  56. ],
  57. [
  58. 'privilege' => '{DAV:}read',
  59. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  60. 'protected' => true,
  61. ],
  62. [
  63. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  64. 'principal' => '{DAV:}authenticated',
  65. 'protected' => true,
  66. ],
  67. ];
  68. }
  69. /**
  70. * @return array
  71. */
  72. public function getChildACL():array {
  73. return [
  74. [
  75. 'privilege' => '{DAV:}read',
  76. 'principal' => $this->getOwner(),
  77. 'protected' => true,
  78. ],
  79. [
  80. 'privilege' => '{DAV:}read',
  81. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  82. 'protected' => true,
  83. ],
  84. [
  85. 'privilege' => '{DAV:}read',
  86. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  87. 'protected' => true,
  88. ],
  89. ];
  90. }
  91. /**
  92. * @return null|string
  93. */
  94. public function getOwner() {
  95. if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  96. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
  97. }
  98. return parent::getOwner();
  99. }
  100. /**
  101. *
  102. */
  103. public function delete() {
  104. $this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
  105. }
  106. /**
  107. * @param PropPatch $propPatch
  108. */
  109. public function propPatch(PropPatch $propPatch) {
  110. $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
  111. }
  112. /**
  113. * @param string $name
  114. * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
  115. * @throws NotFound
  116. */
  117. public function getChild($name) {
  118. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  119. if (!$obj) {
  120. throw new NotFound('Calendar object not found');
  121. }
  122. $obj['acl'] = $this->getChildACL();
  123. return new CachedSubscriptionObject ($this->caldavBackend, $this->calendarInfo, $obj);
  124. }
  125. /**
  126. * @return array
  127. */
  128. public function getChildren():array {
  129. $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  130. $children = [];
  131. foreach($objs as $obj) {
  132. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  133. }
  134. return $children;
  135. }
  136. /**
  137. * @param array $paths
  138. * @return array
  139. */
  140. public function getMultipleChildren(array $paths):array {
  141. $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  142. $children = [];
  143. foreach($objs as $obj) {
  144. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  145. }
  146. return $children;
  147. }
  148. /**
  149. * @param string $name
  150. * @param null $calendarData
  151. * @return null|string|void
  152. * @throws MethodNotAllowed
  153. */
  154. public function createFile($name, $calendarData = null) {
  155. throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
  156. }
  157. /**
  158. * @param string $name
  159. * @return bool
  160. */
  161. public function childExists($name):bool {
  162. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  163. if (!$obj) {
  164. return false;
  165. }
  166. return true;
  167. }
  168. /**
  169. * @param array $filters
  170. * @return array
  171. */
  172. public function calendarQuery(array $filters):array {
  173. return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  174. }
  175. }