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 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCA\DAV\CalDAV;
  26. use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
  27. use Sabre\CalDAV\Backend\BackendInterface;
  28. use Sabre\DAV\Exception\MethodNotAllowed;
  29. use Sabre\DAV\Exception\NotFound;
  30. use Sabre\DAV\PropPatch;
  31. /**
  32. * Class CachedSubscription
  33. *
  34. * @package OCA\DAV\CalDAV
  35. * @property BackendInterface|CalDavBackend $caldavBackend
  36. */
  37. class CachedSubscription extends \Sabre\CalDAV\Calendar {
  38. /**
  39. * @return string
  40. */
  41. public function getPrincipalURI():string {
  42. return $this->calendarInfo['principaluri'];
  43. }
  44. /**
  45. * @return array
  46. */
  47. public function getACL():array {
  48. return [
  49. [
  50. 'privilege' => '{DAV:}read',
  51. 'principal' => $this->getOwner(),
  52. 'protected' => true,
  53. ],
  54. [
  55. 'privilege' => '{DAV:}read',
  56. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  57. 'protected' => true,
  58. ],
  59. [
  60. 'privilege' => '{DAV:}read',
  61. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  62. 'protected' => true,
  63. ],
  64. [
  65. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  66. 'principal' => '{DAV:}authenticated',
  67. 'protected' => true,
  68. ],
  69. ];
  70. }
  71. /**
  72. * @return array
  73. */
  74. public function getChildACL():array {
  75. return [
  76. [
  77. 'privilege' => '{DAV:}read',
  78. 'principal' => $this->getOwner(),
  79. 'protected' => true,
  80. ],
  81. [
  82. 'privilege' => '{DAV:}read',
  83. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  84. 'protected' => true,
  85. ],
  86. [
  87. 'privilege' => '{DAV:}read',
  88. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  89. 'protected' => true,
  90. ],
  91. ];
  92. }
  93. /**
  94. * @return null|string
  95. */
  96. public function getOwner() {
  97. if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  98. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
  99. }
  100. return parent::getOwner();
  101. }
  102. public function delete() {
  103. $this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
  104. }
  105. /**
  106. * @param PropPatch $propPatch
  107. */
  108. public function propPatch(PropPatch $propPatch) {
  109. $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
  110. }
  111. /**
  112. * @param string $name
  113. * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
  114. * @throws NotFound
  115. */
  116. public function getChild($name) {
  117. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  118. if (!$obj) {
  119. throw new NotFound('Calendar object not found');
  120. }
  121. $obj['acl'] = $this->getChildACL();
  122. return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  123. }
  124. /**
  125. * @return array
  126. */
  127. public function getChildren():array {
  128. $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  129. $children = [];
  130. foreach ($objs as $obj) {
  131. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  132. }
  133. return $children;
  134. }
  135. /**
  136. * @param array $paths
  137. * @return array
  138. */
  139. public function getMultipleChildren(array $paths):array {
  140. $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  141. $children = [];
  142. foreach ($objs as $obj) {
  143. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  144. }
  145. return $children;
  146. }
  147. /**
  148. * @param string $name
  149. * @param null $calendarData
  150. * @return null|string|void
  151. * @throws MethodNotAllowed
  152. */
  153. public function createFile($name, $calendarData = null) {
  154. throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
  155. }
  156. /**
  157. * @param string $name
  158. * @return bool
  159. */
  160. public function childExists($name):bool {
  161. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  162. if (!$obj) {
  163. return false;
  164. }
  165. return true;
  166. }
  167. /**
  168. * @param array $filters
  169. * @return array
  170. */
  171. public function calendarQuery(array $filters):array {
  172. return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  173. }
  174. /**
  175. * @inheritDoc
  176. */
  177. public function getChanges($syncToken, $syncLevel, $limit = null) {
  178. if (!$syncToken && $limit) {
  179. throw new UnsupportedLimitOnInitialSyncException();
  180. }
  181. return parent::getChanges($syncToken, $syncLevel, $limit);
  182. }
  183. }