CachedSubscription.php 5.2 KB

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