@@ -44,178 +44,178 @@ |
||
| 44 | 44 | |
| 45 | 45 | class CalendarHome extends \Sabre\CalDAV\CalendarHome { |
| 46 | 46 | |
| 47 | - /** @var \OCP\IL10N */ |
|
| 48 | - private $l10n; |
|
| 49 | - |
|
| 50 | - /** @var \OCP\IConfig */ |
|
| 51 | - private $config; |
|
| 52 | - |
|
| 53 | - /** @var PluginManager */ |
|
| 54 | - private $pluginManager; |
|
| 55 | - |
|
| 56 | - /** @var bool */ |
|
| 57 | - private $returnCachedSubscriptions = false; |
|
| 58 | - |
|
| 59 | - /** @var LoggerInterface */ |
|
| 60 | - private $logger; |
|
| 61 | - |
|
| 62 | - public function __construct(BackendInterface $caldavBackend, $principalInfo, LoggerInterface $logger) { |
|
| 63 | - parent::__construct($caldavBackend, $principalInfo); |
|
| 64 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
| 65 | - $this->config = \OC::$server->getConfig(); |
|
| 66 | - $this->pluginManager = new PluginManager( |
|
| 67 | - \OC::$server, |
|
| 68 | - \OC::$server->getAppManager() |
|
| 69 | - ); |
|
| 70 | - $this->logger = $logger; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @return BackendInterface |
|
| 75 | - */ |
|
| 76 | - public function getCalDAVBackend() { |
|
| 77 | - return $this->caldavBackend; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @inheritdoc |
|
| 82 | - */ |
|
| 83 | - public function createExtendedCollection($name, MkCol $mkCol): void { |
|
| 84 | - $reservedNames = [ |
|
| 85 | - BirthdayService::BIRTHDAY_CALENDAR_URI, |
|
| 86 | - TrashbinHome::NAME, |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
| 90 | - throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - parent::createExtendedCollection($name, $mkCol); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @inheritdoc |
|
| 98 | - */ |
|
| 99 | - public function getChildren() { |
|
| 100 | - $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
| 101 | - $objects = []; |
|
| 102 | - foreach ($calendars as $calendar) { |
|
| 103 | - $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($this->caldavBackend instanceof SchedulingSupport) { |
|
| 107 | - $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 108 | - $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // We're adding a notifications node, if it's supported by the backend. |
|
| 112 | - if ($this->caldavBackend instanceof NotificationSupport) { |
|
| 113 | - $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 117 | - $objects[] = new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // If the backend supports subscriptions, we'll add those as well, |
|
| 121 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 122 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 123 | - if ($this->returnCachedSubscriptions) { |
|
| 124 | - $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
| 125 | - } else { |
|
| 126 | - $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 132 | - /** @var ICalendarProvider $calendarPlugin */ |
|
| 133 | - $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
| 134 | - foreach ($calendars as $calendar) { |
|
| 135 | - $objects[] = $calendar; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $objects; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param string $name |
|
| 144 | - * |
|
| 145 | - * @return INode |
|
| 146 | - */ |
|
| 147 | - public function getChild($name) { |
|
| 148 | - // Special nodes |
|
| 149 | - if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 150 | - return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 151 | - } |
|
| 152 | - if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 153 | - return new Outbox($this->config, $this->principalInfo['uri']); |
|
| 154 | - } |
|
| 155 | - if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
| 156 | - return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 157 | - } |
|
| 158 | - if ($name === TrashbinHome::NAME && $this->caldavBackend instanceof CalDavBackend) { |
|
| 159 | - return new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // Calendar - this covers all "regular" calendars, but not shared |
|
| 163 | - // only check if the method is available |
|
| 164 | - if($this->caldavBackend instanceof CalDavBackend) { |
|
| 165 | - $calendar = $this->caldavBackend->getCalendarByUri($this->principalInfo['uri'], $name); |
|
| 166 | - if(!empty($calendar)) { |
|
| 167 | - return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Fallback to cover shared calendars |
|
| 172 | - foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
| 173 | - if ($calendar['uri'] === $name) { |
|
| 174 | - return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 179 | - foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 180 | - if ($subscription['uri'] === $name) { |
|
| 181 | - if ($this->returnCachedSubscriptions) { |
|
| 182 | - return new CachedSubscription($this->caldavBackend, $subscription); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return new Subscription($this->caldavBackend, $subscription); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
| 191 | - [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 192 | - |
|
| 193 | - foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 194 | - /** @var ICalendarProvider $calendarPlugin */ |
|
| 195 | - if ($calendarPlugin->getAppId() !== $appId) { |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
| 200 | - return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param array $filters |
|
| 210 | - * @param integer|null $limit |
|
| 211 | - * @param integer|null $offset |
|
| 212 | - */ |
|
| 213 | - public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
| 214 | - $principalUri = $this->principalInfo['uri']; |
|
| 215 | - return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function enableCachedSubscriptionsForThisRequest() { |
|
| 219 | - $this->returnCachedSubscriptions = true; |
|
| 220 | - } |
|
| 47 | + /** @var \OCP\IL10N */ |
|
| 48 | + private $l10n; |
|
| 49 | + |
|
| 50 | + /** @var \OCP\IConfig */ |
|
| 51 | + private $config; |
|
| 52 | + |
|
| 53 | + /** @var PluginManager */ |
|
| 54 | + private $pluginManager; |
|
| 55 | + |
|
| 56 | + /** @var bool */ |
|
| 57 | + private $returnCachedSubscriptions = false; |
|
| 58 | + |
|
| 59 | + /** @var LoggerInterface */ |
|
| 60 | + private $logger; |
|
| 61 | + |
|
| 62 | + public function __construct(BackendInterface $caldavBackend, $principalInfo, LoggerInterface $logger) { |
|
| 63 | + parent::__construct($caldavBackend, $principalInfo); |
|
| 64 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
| 65 | + $this->config = \OC::$server->getConfig(); |
|
| 66 | + $this->pluginManager = new PluginManager( |
|
| 67 | + \OC::$server, |
|
| 68 | + \OC::$server->getAppManager() |
|
| 69 | + ); |
|
| 70 | + $this->logger = $logger; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @return BackendInterface |
|
| 75 | + */ |
|
| 76 | + public function getCalDAVBackend() { |
|
| 77 | + return $this->caldavBackend; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @inheritdoc |
|
| 82 | + */ |
|
| 83 | + public function createExtendedCollection($name, MkCol $mkCol): void { |
|
| 84 | + $reservedNames = [ |
|
| 85 | + BirthdayService::BIRTHDAY_CALENDAR_URI, |
|
| 86 | + TrashbinHome::NAME, |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if (\in_array($name, $reservedNames, true) || ExternalCalendar::doesViolateReservedName($name)) { |
|
| 90 | + throw new MethodNotAllowed('The resource you tried to create has a reserved name'); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + parent::createExtendedCollection($name, $mkCol); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @inheritdoc |
|
| 98 | + */ |
|
| 99 | + public function getChildren() { |
|
| 100 | + $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']); |
|
| 101 | + $objects = []; |
|
| 102 | + foreach ($calendars as $calendar) { |
|
| 103 | + $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($this->caldavBackend instanceof SchedulingSupport) { |
|
| 107 | + $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 108 | + $objects[] = new Outbox($this->config, $this->principalInfo['uri']); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // We're adding a notifications node, if it's supported by the backend. |
|
| 112 | + if ($this->caldavBackend instanceof NotificationSupport) { |
|
| 113 | + $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ($this->caldavBackend instanceof CalDavBackend) { |
|
| 117 | + $objects[] = new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // If the backend supports subscriptions, we'll add those as well, |
|
| 121 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 122 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 123 | + if ($this->returnCachedSubscriptions) { |
|
| 124 | + $objects[] = new CachedSubscription($this->caldavBackend, $subscription); |
|
| 125 | + } else { |
|
| 126 | + $objects[] = new Subscription($this->caldavBackend, $subscription); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 132 | + /** @var ICalendarProvider $calendarPlugin */ |
|
| 133 | + $calendars = $calendarPlugin->fetchAllForCalendarHome($this->principalInfo['uri']); |
|
| 134 | + foreach ($calendars as $calendar) { |
|
| 135 | + $objects[] = $calendar; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $objects; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param string $name |
|
| 144 | + * |
|
| 145 | + * @return INode |
|
| 146 | + */ |
|
| 147 | + public function getChild($name) { |
|
| 148 | + // Special nodes |
|
| 149 | + if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 150 | + return new Inbox($this->caldavBackend, $this->principalInfo['uri']); |
|
| 151 | + } |
|
| 152 | + if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) { |
|
| 153 | + return new Outbox($this->config, $this->principalInfo['uri']); |
|
| 154 | + } |
|
| 155 | + if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) { |
|
| 156 | + return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']); |
|
| 157 | + } |
|
| 158 | + if ($name === TrashbinHome::NAME && $this->caldavBackend instanceof CalDavBackend) { |
|
| 159 | + return new TrashbinHome($this->caldavBackend, $this->principalInfo); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // Calendar - this covers all "regular" calendars, but not shared |
|
| 163 | + // only check if the method is available |
|
| 164 | + if($this->caldavBackend instanceof CalDavBackend) { |
|
| 165 | + $calendar = $this->caldavBackend->getCalendarByUri($this->principalInfo['uri'], $name); |
|
| 166 | + if(!empty($calendar)) { |
|
| 167 | + return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Fallback to cover shared calendars |
|
| 172 | + foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) { |
|
| 173 | + if ($calendar['uri'] === $name) { |
|
| 174 | + return new Calendar($this->caldavBackend, $calendar, $this->l10n, $this->config, $this->logger); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($this->caldavBackend instanceof SubscriptionSupport) { |
|
| 179 | + foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) { |
|
| 180 | + if ($subscription['uri'] === $name) { |
|
| 181 | + if ($this->returnCachedSubscriptions) { |
|
| 182 | + return new CachedSubscription($this->caldavBackend, $subscription); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return new Subscription($this->caldavBackend, $subscription); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (ExternalCalendar::isAppGeneratedCalendar($name)) { |
|
| 191 | + [$appId, $calendarUri] = ExternalCalendar::splitAppGeneratedCalendarUri($name); |
|
| 192 | + |
|
| 193 | + foreach ($this->pluginManager->getCalendarPlugins() as $calendarPlugin) { |
|
| 194 | + /** @var ICalendarProvider $calendarPlugin */ |
|
| 195 | + if ($calendarPlugin->getAppId() !== $appId) { |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if ($calendarPlugin->hasCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri)) { |
|
| 200 | + return $calendarPlugin->getCalendarInCalendarHome($this->principalInfo['uri'], $calendarUri); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + throw new NotFound('Node with name \'' . $name . '\' could not be found'); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param array $filters |
|
| 210 | + * @param integer|null $limit |
|
| 211 | + * @param integer|null $offset |
|
| 212 | + */ |
|
| 213 | + public function calendarSearch(array $filters, $limit = null, $offset = null) { |
|
| 214 | + $principalUri = $this->principalInfo['uri']; |
|
| 215 | + return $this->caldavBackend->calendarSearch($principalUri, $filters, $limit, $offset); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + public function enableCachedSubscriptionsForThisRequest() { |
|
| 219 | + $this->returnCachedSubscriptions = true; |
|
| 220 | + } |
|
| 221 | 221 | } |