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.3KB

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\INode;
  32. use Sabre\DAV\PropPatch;
  33. /**
  34. * Class CachedSubscription
  35. *
  36. * @package OCA\DAV\CalDAV
  37. * @property BackendInterface|CalDavBackend $caldavBackend
  38. */
  39. class CachedSubscription extends \Sabre\CalDAV\Calendar {
  40. /**
  41. * @return string
  42. */
  43. public function getPrincipalURI():string {
  44. return $this->calendarInfo['principaluri'];
  45. }
  46. /**
  47. * @return array
  48. */
  49. public function getACL() {
  50. return [
  51. [
  52. 'privilege' => '{DAV:}read',
  53. 'principal' => $this->getOwner(),
  54. 'protected' => true,
  55. ],
  56. [
  57. 'privilege' => '{DAV:}read',
  58. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  59. 'protected' => true,
  60. ],
  61. [
  62. 'privilege' => '{DAV:}read',
  63. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  64. 'protected' => true,
  65. ],
  66. [
  67. 'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
  68. 'principal' => '{DAV:}authenticated',
  69. 'protected' => true,
  70. ],
  71. ];
  72. }
  73. /**
  74. * @return array
  75. */
  76. public function getChildACL() {
  77. return [
  78. [
  79. 'privilege' => '{DAV:}read',
  80. 'principal' => $this->getOwner(),
  81. 'protected' => true,
  82. ],
  83. [
  84. 'privilege' => '{DAV:}read',
  85. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  86. 'protected' => true,
  87. ],
  88. [
  89. 'privilege' => '{DAV:}read',
  90. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  91. 'protected' => true,
  92. ],
  93. ];
  94. }
  95. /**
  96. * @return null|string
  97. */
  98. public function getOwner() {
  99. if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  100. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
  101. }
  102. return parent::getOwner();
  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 INode[]
  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|resource|string $calendarData
  152. * @return null|string
  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. }