CachedSubscription.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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\DAV\Exception\MethodNotAllowed;
  29. use Sabre\DAV\Exception\NotFound;
  30. use Sabre\DAV\INode;
  31. use Sabre\DAV\PropPatch;
  32. /**
  33. * Class CachedSubscription
  34. *
  35. * @package OCA\DAV\CalDAV
  36. * @property 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() {
  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. 'privilege' => '{DAV:}write-properties',
  72. 'principal' => $this->getOwner(),
  73. 'protected' => true,
  74. ]
  75. ];
  76. }
  77. /**
  78. * @return array
  79. */
  80. public function getChildACL() {
  81. return [
  82. [
  83. 'privilege' => '{DAV:}read',
  84. 'principal' => $this->getOwner(),
  85. 'protected' => true,
  86. ],
  87. [
  88. 'privilege' => '{DAV:}read',
  89. 'principal' => $this->getOwner() . '/calendar-proxy-write',
  90. 'protected' => true,
  91. ],
  92. [
  93. 'privilege' => '{DAV:}read',
  94. 'principal' => $this->getOwner() . '/calendar-proxy-read',
  95. 'protected' => true,
  96. ],
  97. ];
  98. }
  99. /**
  100. * @return null|string
  101. */
  102. public function getOwner() {
  103. if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
  104. return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
  105. }
  106. return parent::getOwner();
  107. }
  108. public function delete() {
  109. $this->caldavBackend->deleteSubscription($this->calendarInfo['id']);
  110. }
  111. /**
  112. * @param PropPatch $propPatch
  113. */
  114. public function propPatch(PropPatch $propPatch) {
  115. $this->caldavBackend->updateSubscription($this->calendarInfo['id'], $propPatch);
  116. }
  117. /**
  118. * @param string $name
  119. * @return CalendarObject|\Sabre\CalDAV\ICalendarObject
  120. * @throws NotFound
  121. */
  122. public function getChild($name) {
  123. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  124. if (!$obj) {
  125. throw new NotFound('Calendar object not found');
  126. }
  127. $obj['acl'] = $this->getChildACL();
  128. return new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  129. }
  130. /**
  131. * @return INode[]
  132. */
  133. public function getChildren(): array {
  134. $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id'], CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  135. $children = [];
  136. foreach ($objs as $obj) {
  137. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  138. }
  139. return $children;
  140. }
  141. /**
  142. * @param array $paths
  143. * @return array
  144. */
  145. public function getMultipleChildren(array $paths):array {
  146. $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  147. $children = [];
  148. foreach ($objs as $obj) {
  149. $children[] = new CachedSubscriptionObject($this->caldavBackend, $this->calendarInfo, $obj);
  150. }
  151. return $children;
  152. }
  153. /**
  154. * @param string $name
  155. * @param null|resource|string $data
  156. * @return null|string
  157. * @throws MethodNotAllowed
  158. */
  159. public function createFile($name, $data = null) {
  160. throw new MethodNotAllowed('Creating objects in cached subscription is not allowed');
  161. }
  162. /**
  163. * @param string $name
  164. * @return bool
  165. */
  166. public function childExists($name):bool {
  167. $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  168. if (!$obj) {
  169. return false;
  170. }
  171. return true;
  172. }
  173. /**
  174. * @param array $filters
  175. * @return array
  176. */
  177. public function calendarQuery(array $filters):array {
  178. return $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
  179. }
  180. /**
  181. * @inheritDoc
  182. */
  183. public function getChanges($syncToken, $syncLevel, $limit = null) {
  184. if (!$syncToken && $limit) {
  185. throw new UnsupportedLimitOnInitialSyncException();
  186. }
  187. return parent::getChanges($syncToken, $syncLevel, $limit);
  188. }
  189. }