CachedSubscription.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license GNU AGPL version 3 or any later version
  11. *
  12. * This program is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License as
  14. * published by the Free Software Foundation, either version 3 of the
  15. * License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. *
  25. */
  26. namespace OCA\DAV\CalDAV;
  27. use OCA\DAV\Exception\UnsupportedLimitOnInitialSyncException;
  28. use Sabre\CalDAV\Backend\BackendInterface;
  29. use Sabre\DAV\Exception\MethodNotAllowed;
  30. use Sabre\DAV\Exception\NotFound;
  31. use Sabre\DAV\PropPatch;
  32. /**
  33. * Class CachedSubscription
  34. *
  35. * @package OCA\DAV\CalDAV
  36. * @property BackendInterface|CalDavBackend $caldavBackend
  37. */
  38. class CachedSubscription extends \Sabre\CalDAV\Calendar {
  39. /**
  40. * @return string
  41. */
  42. public function getPrincipalURI():string {
  43. return $this->calendarInfo['principaluri'];
  44. }
  45. /**
  46. * @return array
  47. */
  48. public function getACL():array {
  49. return [
  50. [
  51. 'privilege' => '{DAV:}read',
  52. 'principal' => $this->getOwner(),
  53. 'protected' => true,
  54. ],
  55. [
  56. 'privilege' => '{DAV:}read',
  57. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  58. 'protected' => true,
  59. ],
  60. [
  61. 'privilege' => '{DAV:}read',
  62. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  63. 'protected' => true,
  64. ],
  65. [
  66. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  67. 'principal' => '{DAV:}authenticated',
  68. 'protected' => true,
  69. ],
  70. ];
  71. }
  72. /**
  73. * @return array
  74. */
  75. public function getChildACL():array {
  76. return [
  77. [
  78. 'privilege' => '{DAV:}read',
  79. 'principal' => $this->getOwner(),
  80. 'protected' => true,
  81. ],
  82. [
  83. 'privilege' => '{DAV:}read',
  84. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  85. 'protected' => true,
  86. ],
  87. [
  88. 'privilege' => '{DAV:}read',
  89. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  90. 'protected' => true,
  91. ],
  92. ];
  93. }
  94. /**
  95. * @return null|string
  96. */
  97. public function getOwner() {
  98. if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  99. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
  100. }
  101. return parent::getOwner();
  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. /**
  176. * @inheritDoc
  177. */
  178. public function getChanges($syncToken, $syncLevel, $limit = null) {
  179. if (!$syncToken && $limit) {
  180. throw new UnsupportedLimitOnInitialSyncException();
  181. }
  182. return parent::getChanges($syncToken, $syncLevel, $limit);
  183. }
  184. }