@@ -42,301 +42,301 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
| 44 | 44 | |
| 45 | - /** @var IConfig */ |
|
| 46 | - private $config; |
|
| 47 | - |
|
| 48 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
| 49 | - parent::__construct($caldavBackend, $calendarInfo); |
|
| 50 | - |
|
| 51 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 52 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 53 | - } |
|
| 54 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 55 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 56 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $this->config = $config; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Updates the list of shares. |
|
| 64 | - * |
|
| 65 | - * The first array is a list of people that are to be added to the |
|
| 66 | - * resource. |
|
| 67 | - * |
|
| 68 | - * Every element in the add array has the following properties: |
|
| 69 | - * * href - A url. Usually a mailto: address |
|
| 70 | - * * commonName - Usually a first and last name, or false |
|
| 71 | - * * summary - A description of the share, can also be false |
|
| 72 | - * * readOnly - A boolean value |
|
| 73 | - * |
|
| 74 | - * Every element in the remove array is just the address string. |
|
| 75 | - * |
|
| 76 | - * @param array $add |
|
| 77 | - * @param array $remove |
|
| 78 | - * @return void |
|
| 79 | - * @throws Forbidden |
|
| 80 | - */ |
|
| 81 | - public function updateShares(array $add, array $remove) { |
|
| 82 | - if ($this->isShared()) { |
|
| 83 | - throw new Forbidden(); |
|
| 84 | - } |
|
| 85 | - $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Returns the list of people whom this resource is shared with. |
|
| 90 | - * |
|
| 91 | - * Every element in this array should have the following properties: |
|
| 92 | - * * href - Often a mailto: address |
|
| 93 | - * * commonName - Optional, for example a first + last name |
|
| 94 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 95 | - * * readOnly - boolean |
|
| 96 | - * * summary - Optional, a description for the share |
|
| 97 | - * |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - public function getShares() { |
|
| 101 | - if ($this->isShared()) { |
|
| 102 | - return []; |
|
| 103 | - } |
|
| 104 | - return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return int |
|
| 109 | - */ |
|
| 110 | - public function getResourceId() { |
|
| 111 | - return $this->calendarInfo['id']; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function getPrincipalURI() { |
|
| 118 | - return $this->calendarInfo['principaluri']; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function getACL() { |
|
| 122 | - $acl = [ |
|
| 123 | - [ |
|
| 124 | - 'privilege' => '{DAV:}read', |
|
| 125 | - 'principal' => $this->getOwner(), |
|
| 126 | - 'protected' => true, |
|
| 127 | - ]]; |
|
| 128 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 129 | - $acl[] = [ |
|
| 130 | - 'privilege' => '{DAV:}write', |
|
| 131 | - 'principal' => $this->getOwner(), |
|
| 132 | - 'protected' => true, |
|
| 133 | - ]; |
|
| 134 | - } else { |
|
| 135 | - $acl[] = [ |
|
| 136 | - 'privilege' => '{DAV:}write-properties', |
|
| 137 | - 'principal' => $this->getOwner(), |
|
| 138 | - 'protected' => true, |
|
| 139 | - ]; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if (!$this->isShared()) { |
|
| 143 | - return $acl; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 147 | - $acl[] = [ |
|
| 148 | - 'privilege' => '{DAV:}read', |
|
| 149 | - 'principal' => parent::getOwner(), |
|
| 150 | - 'protected' => true, |
|
| 151 | - ]; |
|
| 152 | - if ($this->canWrite()) { |
|
| 153 | - $acl[] = [ |
|
| 154 | - 'privilege' => '{DAV:}write', |
|
| 155 | - 'principal' => parent::getOwner(), |
|
| 156 | - 'protected' => true, |
|
| 157 | - ]; |
|
| 158 | - } else { |
|
| 159 | - $acl[] = [ |
|
| 160 | - 'privilege' => '{DAV:}write-properties', |
|
| 161 | - 'principal' => parent::getOwner(), |
|
| 162 | - 'protected' => true, |
|
| 163 | - ]; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - if ($this->isPublic()) { |
|
| 167 | - $acl[] = [ |
|
| 168 | - 'privilege' => '{DAV:}read', |
|
| 169 | - 'principal' => 'principals/system/public', |
|
| 170 | - 'protected' => true, |
|
| 171 | - ]; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 175 | - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
| 176 | - return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 177 | - return \in_array($rule['principal'], $allowedPrincipals, true); |
|
| 178 | - }); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - public function getChildACL() { |
|
| 182 | - return $this->getACL(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - public function getOwner() { |
|
| 186 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 187 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 188 | - } |
|
| 189 | - return parent::getOwner(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function delete() { |
|
| 193 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 194 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 195 | - $principal = 'principal:' . parent::getOwner(); |
|
| 196 | - $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 197 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 198 | - return $share['href'] === $principal; |
|
| 199 | - }); |
|
| 200 | - if (empty($shares)) { |
|
| 201 | - throw new Forbidden(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $this->caldavBackend->updateShares($this, [], [ |
|
| 205 | - $principal |
|
| 206 | - ]); |
|
| 207 | - return; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Remember when a user deleted their birthday calendar |
|
| 211 | - // in order to not regenerate it on the next contacts change |
|
| 212 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 213 | - $principalURI = $this->getPrincipalURI(); |
|
| 214 | - $userId = substr($principalURI, 17); |
|
| 215 | - |
|
| 216 | - $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - parent::delete(); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - public function propPatch(PropPatch $propPatch) { |
|
| 223 | - // parent::propPatch will only update calendars table |
|
| 224 | - // if calendar is shared, changes have to be made to the properties table |
|
| 225 | - if (!$this->isShared()) { |
|
| 226 | - parent::propPatch($propPatch); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - public function getChild($name) { |
|
| 231 | - |
|
| 232 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 233 | - |
|
| 234 | - if (!$obj) { |
|
| 235 | - throw new NotFound('Calendar object not found'); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 239 | - throw new NotFound('Calendar object not found'); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $obj['acl'] = $this->getChildACL(); |
|
| 243 | - |
|
| 244 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 245 | - |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - public function getChildren() { |
|
| 249 | - |
|
| 250 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 251 | - $children = []; |
|
| 252 | - foreach ($objs as $obj) { |
|
| 253 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 254 | - continue; |
|
| 255 | - } |
|
| 256 | - $obj['acl'] = $this->getChildACL(); |
|
| 257 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 258 | - } |
|
| 259 | - return $children; |
|
| 260 | - |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - public function getMultipleChildren(array $paths) { |
|
| 264 | - |
|
| 265 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 266 | - $children = []; |
|
| 267 | - foreach ($objs as $obj) { |
|
| 268 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 269 | - continue; |
|
| 270 | - } |
|
| 271 | - $obj['acl'] = $this->getChildACL(); |
|
| 272 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 273 | - } |
|
| 274 | - return $children; |
|
| 275 | - |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - public function childExists($name) { |
|
| 279 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 280 | - if (!$obj) { |
|
| 281 | - return false; |
|
| 282 | - } |
|
| 283 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return true; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - public function calendarQuery(array $filters) { |
|
| 291 | - |
|
| 292 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 293 | - if ($this->isShared()) { |
|
| 294 | - return array_filter($uris, function ($uri) { |
|
| 295 | - return $this->childExists($uri); |
|
| 296 | - }); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $uris; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @param boolean $value |
|
| 304 | - * @return string|null |
|
| 305 | - */ |
|
| 306 | - public function setPublishStatus($value) { |
|
| 307 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 308 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
| 309 | - return $publicUri; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @return mixed $value |
|
| 314 | - */ |
|
| 315 | - public function getPublishStatus() { |
|
| 316 | - return $this->caldavBackend->getPublishStatus($this); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - private function canWrite() { |
|
| 320 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 321 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 322 | - } |
|
| 323 | - return true; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - private function isPublic() { |
|
| 327 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - protected function isShared() { |
|
| 331 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - public function isSubscription() { |
|
| 339 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 340 | - } |
|
| 45 | + /** @var IConfig */ |
|
| 46 | + private $config; |
|
| 47 | + |
|
| 48 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n, IConfig $config) { |
|
| 49 | + parent::__construct($caldavBackend, $calendarInfo); |
|
| 50 | + |
|
| 51 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 52 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 53 | + } |
|
| 54 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 55 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 56 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $this->config = $config; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Updates the list of shares. |
|
| 64 | + * |
|
| 65 | + * The first array is a list of people that are to be added to the |
|
| 66 | + * resource. |
|
| 67 | + * |
|
| 68 | + * Every element in the add array has the following properties: |
|
| 69 | + * * href - A url. Usually a mailto: address |
|
| 70 | + * * commonName - Usually a first and last name, or false |
|
| 71 | + * * summary - A description of the share, can also be false |
|
| 72 | + * * readOnly - A boolean value |
|
| 73 | + * |
|
| 74 | + * Every element in the remove array is just the address string. |
|
| 75 | + * |
|
| 76 | + * @param array $add |
|
| 77 | + * @param array $remove |
|
| 78 | + * @return void |
|
| 79 | + * @throws Forbidden |
|
| 80 | + */ |
|
| 81 | + public function updateShares(array $add, array $remove) { |
|
| 82 | + if ($this->isShared()) { |
|
| 83 | + throw new Forbidden(); |
|
| 84 | + } |
|
| 85 | + $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Returns the list of people whom this resource is shared with. |
|
| 90 | + * |
|
| 91 | + * Every element in this array should have the following properties: |
|
| 92 | + * * href - Often a mailto: address |
|
| 93 | + * * commonName - Optional, for example a first + last name |
|
| 94 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 95 | + * * readOnly - boolean |
|
| 96 | + * * summary - Optional, a description for the share |
|
| 97 | + * |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + public function getShares() { |
|
| 101 | + if ($this->isShared()) { |
|
| 102 | + return []; |
|
| 103 | + } |
|
| 104 | + return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return int |
|
| 109 | + */ |
|
| 110 | + public function getResourceId() { |
|
| 111 | + return $this->calendarInfo['id']; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function getPrincipalURI() { |
|
| 118 | + return $this->calendarInfo['principaluri']; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function getACL() { |
|
| 122 | + $acl = [ |
|
| 123 | + [ |
|
| 124 | + 'privilege' => '{DAV:}read', |
|
| 125 | + 'principal' => $this->getOwner(), |
|
| 126 | + 'protected' => true, |
|
| 127 | + ]]; |
|
| 128 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 129 | + $acl[] = [ |
|
| 130 | + 'privilege' => '{DAV:}write', |
|
| 131 | + 'principal' => $this->getOwner(), |
|
| 132 | + 'protected' => true, |
|
| 133 | + ]; |
|
| 134 | + } else { |
|
| 135 | + $acl[] = [ |
|
| 136 | + 'privilege' => '{DAV:}write-properties', |
|
| 137 | + 'principal' => $this->getOwner(), |
|
| 138 | + 'protected' => true, |
|
| 139 | + ]; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if (!$this->isShared()) { |
|
| 143 | + return $acl; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 147 | + $acl[] = [ |
|
| 148 | + 'privilege' => '{DAV:}read', |
|
| 149 | + 'principal' => parent::getOwner(), |
|
| 150 | + 'protected' => true, |
|
| 151 | + ]; |
|
| 152 | + if ($this->canWrite()) { |
|
| 153 | + $acl[] = [ |
|
| 154 | + 'privilege' => '{DAV:}write', |
|
| 155 | + 'principal' => parent::getOwner(), |
|
| 156 | + 'protected' => true, |
|
| 157 | + ]; |
|
| 158 | + } else { |
|
| 159 | + $acl[] = [ |
|
| 160 | + 'privilege' => '{DAV:}write-properties', |
|
| 161 | + 'principal' => parent::getOwner(), |
|
| 162 | + 'protected' => true, |
|
| 163 | + ]; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + if ($this->isPublic()) { |
|
| 167 | + $acl[] = [ |
|
| 168 | + 'privilege' => '{DAV:}read', |
|
| 169 | + 'principal' => 'principals/system/public', |
|
| 170 | + 'protected' => true, |
|
| 171 | + ]; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 175 | + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
| 176 | + return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 177 | + return \in_array($rule['principal'], $allowedPrincipals, true); |
|
| 178 | + }); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + public function getChildACL() { |
|
| 182 | + return $this->getACL(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + public function getOwner() { |
|
| 186 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 187 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 188 | + } |
|
| 189 | + return parent::getOwner(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function delete() { |
|
| 193 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 194 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 195 | + $principal = 'principal:' . parent::getOwner(); |
|
| 196 | + $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 197 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 198 | + return $share['href'] === $principal; |
|
| 199 | + }); |
|
| 200 | + if (empty($shares)) { |
|
| 201 | + throw new Forbidden(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $this->caldavBackend->updateShares($this, [], [ |
|
| 205 | + $principal |
|
| 206 | + ]); |
|
| 207 | + return; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Remember when a user deleted their birthday calendar |
|
| 211 | + // in order to not regenerate it on the next contacts change |
|
| 212 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 213 | + $principalURI = $this->getPrincipalURI(); |
|
| 214 | + $userId = substr($principalURI, 17); |
|
| 215 | + |
|
| 216 | + $this->config->setUserValue($userId, 'dav', 'generateBirthdayCalendar', 'no'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + parent::delete(); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + public function propPatch(PropPatch $propPatch) { |
|
| 223 | + // parent::propPatch will only update calendars table |
|
| 224 | + // if calendar is shared, changes have to be made to the properties table |
|
| 225 | + if (!$this->isShared()) { |
|
| 226 | + parent::propPatch($propPatch); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + public function getChild($name) { |
|
| 231 | + |
|
| 232 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 233 | + |
|
| 234 | + if (!$obj) { |
|
| 235 | + throw new NotFound('Calendar object not found'); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 239 | + throw new NotFound('Calendar object not found'); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $obj['acl'] = $this->getChildACL(); |
|
| 243 | + |
|
| 244 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 245 | + |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + public function getChildren() { |
|
| 249 | + |
|
| 250 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 251 | + $children = []; |
|
| 252 | + foreach ($objs as $obj) { |
|
| 253 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 254 | + continue; |
|
| 255 | + } |
|
| 256 | + $obj['acl'] = $this->getChildACL(); |
|
| 257 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 258 | + } |
|
| 259 | + return $children; |
|
| 260 | + |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + public function getMultipleChildren(array $paths) { |
|
| 264 | + |
|
| 265 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 266 | + $children = []; |
|
| 267 | + foreach ($objs as $obj) { |
|
| 268 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 269 | + continue; |
|
| 270 | + } |
|
| 271 | + $obj['acl'] = $this->getChildACL(); |
|
| 272 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 273 | + } |
|
| 274 | + return $children; |
|
| 275 | + |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + public function childExists($name) { |
|
| 279 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 280 | + if (!$obj) { |
|
| 281 | + return false; |
|
| 282 | + } |
|
| 283 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return true; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + public function calendarQuery(array $filters) { |
|
| 291 | + |
|
| 292 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 293 | + if ($this->isShared()) { |
|
| 294 | + return array_filter($uris, function ($uri) { |
|
| 295 | + return $this->childExists($uri); |
|
| 296 | + }); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $uris; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @param boolean $value |
|
| 304 | + * @return string|null |
|
| 305 | + */ |
|
| 306 | + public function setPublishStatus($value) { |
|
| 307 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 308 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
| 309 | + return $publicUri; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * @return mixed $value |
|
| 314 | + */ |
|
| 315 | + public function getPublishStatus() { |
|
| 316 | + return $this->caldavBackend->getPublishStatus($this); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + private function canWrite() { |
|
| 320 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 321 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 322 | + } |
|
| 323 | + return true; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + private function isPublic() { |
|
| 327 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + protected function isShared() { |
|
| 331 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + public function isSubscription() { |
|
| 339 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | } |
@@ -38,184 +38,184 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * AddressBook constructor. |
|
| 43 | - * |
|
| 44 | - * @param BackendInterface $carddavBackend |
|
| 45 | - * @param array $addressBookInfo |
|
| 46 | - * @param IL10N $l10n |
|
| 47 | - */ |
|
| 48 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 49 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
| 50 | - |
|
| 51 | - if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 52 | - $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 53 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Updates the list of shares. |
|
| 59 | - * |
|
| 60 | - * The first array is a list of people that are to be added to the |
|
| 61 | - * addressbook. |
|
| 62 | - * |
|
| 63 | - * Every element in the add array has the following properties: |
|
| 64 | - * * href - A url. Usually a mailto: address |
|
| 65 | - * * commonName - Usually a first and last name, or false |
|
| 66 | - * * summary - A description of the share, can also be false |
|
| 67 | - * * readOnly - A boolean value |
|
| 68 | - * |
|
| 69 | - * Every element in the remove array is just the address string. |
|
| 70 | - * |
|
| 71 | - * @param array $add |
|
| 72 | - * @param array $remove |
|
| 73 | - * @return void |
|
| 74 | - * @throws Forbidden |
|
| 75 | - */ |
|
| 76 | - public function updateShares(array $add, array $remove) { |
|
| 77 | - if ($this->isShared()) { |
|
| 78 | - throw new Forbidden(); |
|
| 79 | - } |
|
| 80 | - $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Returns the list of people whom this addressbook is shared with. |
|
| 85 | - * |
|
| 86 | - * Every element in this array should have the following properties: |
|
| 87 | - * * href - Often a mailto: address |
|
| 88 | - * * commonName - Optional, for example a first + last name |
|
| 89 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 90 | - * * readOnly - boolean |
|
| 91 | - * * summary - Optional, a description for the share |
|
| 92 | - * |
|
| 93 | - * @return array |
|
| 94 | - */ |
|
| 95 | - public function getShares() { |
|
| 96 | - if ($this->isShared()) { |
|
| 97 | - return []; |
|
| 98 | - } |
|
| 99 | - return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - public function getACL() { |
|
| 103 | - $acl = [ |
|
| 104 | - [ |
|
| 105 | - 'privilege' => '{DAV:}read', |
|
| 106 | - 'principal' => $this->getOwner(), |
|
| 107 | - 'protected' => true, |
|
| 108 | - ],[ |
|
| 109 | - 'privilege' => '{DAV:}write', |
|
| 110 | - 'principal' => $this->getOwner(), |
|
| 111 | - 'protected' => true, |
|
| 112 | - ] |
|
| 113 | - ]; |
|
| 114 | - |
|
| 115 | - if (!$this->isShared()) { |
|
| 116 | - return $acl; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 120 | - $acl[] = [ |
|
| 121 | - 'privilege' => '{DAV:}read', |
|
| 122 | - 'principal' => parent::getOwner(), |
|
| 123 | - 'protected' => true, |
|
| 124 | - ]; |
|
| 125 | - if ($this->canWrite()) { |
|
| 126 | - $acl[] = [ |
|
| 127 | - 'privilege' => '{DAV:}write', |
|
| 128 | - 'principal' => parent::getOwner(), |
|
| 129 | - 'protected' => true, |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - if ($this->getOwner() === 'principals/system/system') { |
|
| 134 | - $acl[] = [ |
|
| 135 | - 'privilege' => '{DAV:}read', |
|
| 136 | - 'principal' => '{DAV:}authenticated', |
|
| 137 | - 'protected' => true, |
|
| 138 | - ]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $acl = $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 142 | - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system']; |
|
| 143 | - return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 144 | - return \in_array($rule['principal'], $allowedPrincipals, true); |
|
| 145 | - }); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function getChildACL() { |
|
| 149 | - return $this->getACL(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - public function getChild($name) { |
|
| 153 | - |
|
| 154 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 155 | - if (!$obj) { |
|
| 156 | - throw new NotFound('Card not found'); |
|
| 157 | - } |
|
| 158 | - $obj['acl'] = $this->getChildACL(); |
|
| 159 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 160 | - |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @return int |
|
| 165 | - */ |
|
| 166 | - public function getResourceId() { |
|
| 167 | - return $this->addressBookInfo['id']; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - public function getOwner() { |
|
| 171 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 172 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 173 | - } |
|
| 174 | - return parent::getOwner(); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function delete() { |
|
| 178 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 179 | - $principal = 'principal:' . parent::getOwner(); |
|
| 180 | - $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 181 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 182 | - return $share['href'] === $principal; |
|
| 183 | - }); |
|
| 184 | - if (empty($shares)) { |
|
| 185 | - throw new Forbidden(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $this->carddavBackend->updateShares($this, [], [ |
|
| 189 | - $principal |
|
| 190 | - ]); |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - parent::delete(); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - public function propPatch(PropPatch $propPatch) { |
|
| 197 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 198 | - throw new Forbidden(); |
|
| 199 | - } |
|
| 200 | - parent::propPatch($propPatch); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - public function getContactsGroups() { |
|
| 204 | - return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - private function isShared() { |
|
| 208 | - if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - private function canWrite() { |
|
| 216 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 217 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 218 | - } |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 41 | + /** |
|
| 42 | + * AddressBook constructor. |
|
| 43 | + * |
|
| 44 | + * @param BackendInterface $carddavBackend |
|
| 45 | + * @param array $addressBookInfo |
|
| 46 | + * @param IL10N $l10n |
|
| 47 | + */ |
|
| 48 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
| 49 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
| 50 | + |
|
| 51 | + if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
| 52 | + $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
| 53 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Updates the list of shares. |
|
| 59 | + * |
|
| 60 | + * The first array is a list of people that are to be added to the |
|
| 61 | + * addressbook. |
|
| 62 | + * |
|
| 63 | + * Every element in the add array has the following properties: |
|
| 64 | + * * href - A url. Usually a mailto: address |
|
| 65 | + * * commonName - Usually a first and last name, or false |
|
| 66 | + * * summary - A description of the share, can also be false |
|
| 67 | + * * readOnly - A boolean value |
|
| 68 | + * |
|
| 69 | + * Every element in the remove array is just the address string. |
|
| 70 | + * |
|
| 71 | + * @param array $add |
|
| 72 | + * @param array $remove |
|
| 73 | + * @return void |
|
| 74 | + * @throws Forbidden |
|
| 75 | + */ |
|
| 76 | + public function updateShares(array $add, array $remove) { |
|
| 77 | + if ($this->isShared()) { |
|
| 78 | + throw new Forbidden(); |
|
| 79 | + } |
|
| 80 | + $this->carddavBackend->updateShares($this, $add, $remove); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Returns the list of people whom this addressbook is shared with. |
|
| 85 | + * |
|
| 86 | + * Every element in this array should have the following properties: |
|
| 87 | + * * href - Often a mailto: address |
|
| 88 | + * * commonName - Optional, for example a first + last name |
|
| 89 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 90 | + * * readOnly - boolean |
|
| 91 | + * * summary - Optional, a description for the share |
|
| 92 | + * |
|
| 93 | + * @return array |
|
| 94 | + */ |
|
| 95 | + public function getShares() { |
|
| 96 | + if ($this->isShared()) { |
|
| 97 | + return []; |
|
| 98 | + } |
|
| 99 | + return $this->carddavBackend->getShares($this->getResourceId()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + public function getACL() { |
|
| 103 | + $acl = [ |
|
| 104 | + [ |
|
| 105 | + 'privilege' => '{DAV:}read', |
|
| 106 | + 'principal' => $this->getOwner(), |
|
| 107 | + 'protected' => true, |
|
| 108 | + ],[ |
|
| 109 | + 'privilege' => '{DAV:}write', |
|
| 110 | + 'principal' => $this->getOwner(), |
|
| 111 | + 'protected' => true, |
|
| 112 | + ] |
|
| 113 | + ]; |
|
| 114 | + |
|
| 115 | + if (!$this->isShared()) { |
|
| 116 | + return $acl; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 120 | + $acl[] = [ |
|
| 121 | + 'privilege' => '{DAV:}read', |
|
| 122 | + 'principal' => parent::getOwner(), |
|
| 123 | + 'protected' => true, |
|
| 124 | + ]; |
|
| 125 | + if ($this->canWrite()) { |
|
| 126 | + $acl[] = [ |
|
| 127 | + 'privilege' => '{DAV:}write', |
|
| 128 | + 'principal' => parent::getOwner(), |
|
| 129 | + 'protected' => true, |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + if ($this->getOwner() === 'principals/system/system') { |
|
| 134 | + $acl[] = [ |
|
| 135 | + 'privilege' => '{DAV:}read', |
|
| 136 | + 'principal' => '{DAV:}authenticated', |
|
| 137 | + 'protected' => true, |
|
| 138 | + ]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $acl = $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 142 | + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/system']; |
|
| 143 | + return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 144 | + return \in_array($rule['principal'], $allowedPrincipals, true); |
|
| 145 | + }); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function getChildACL() { |
|
| 149 | + return $this->getACL(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + public function getChild($name) { |
|
| 153 | + |
|
| 154 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
| 155 | + if (!$obj) { |
|
| 156 | + throw new NotFound('Card not found'); |
|
| 157 | + } |
|
| 158 | + $obj['acl'] = $this->getChildACL(); |
|
| 159 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
| 160 | + |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @return int |
|
| 165 | + */ |
|
| 166 | + public function getResourceId() { |
|
| 167 | + return $this->addressBookInfo['id']; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + public function getOwner() { |
|
| 171 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 172 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 173 | + } |
|
| 174 | + return parent::getOwner(); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function delete() { |
|
| 178 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 179 | + $principal = 'principal:' . parent::getOwner(); |
|
| 180 | + $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
| 181 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 182 | + return $share['href'] === $principal; |
|
| 183 | + }); |
|
| 184 | + if (empty($shares)) { |
|
| 185 | + throw new Forbidden(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $this->carddavBackend->updateShares($this, [], [ |
|
| 189 | + $principal |
|
| 190 | + ]); |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + parent::delete(); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + public function propPatch(PropPatch $propPatch) { |
|
| 197 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 198 | + throw new Forbidden(); |
|
| 199 | + } |
|
| 200 | + parent::propPatch($propPatch); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + public function getContactsGroups() { |
|
| 204 | + return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + private function isShared() { |
|
| 208 | + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + private function canWrite() { |
|
| 216 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 217 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
| 218 | + } |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -100,12 +100,12 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function getACL() { |
| 103 | - $acl = [ |
|
| 103 | + $acl = [ |
|
| 104 | 104 | [ |
| 105 | 105 | 'privilege' => '{DAV:}read', |
| 106 | 106 | 'principal' => $this->getOwner(), |
| 107 | 107 | 'protected' => true, |
| 108 | - ],[ |
|
| 108 | + ], [ |
|
| 109 | 109 | 'privilege' => '{DAV:}write', |
| 110 | 110 | 'principal' => $this->getOwner(), |
| 111 | 111 | 'protected' => true, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | if ($this->getOwner() !== parent::getOwner()) { |
| 120 | - $acl[] = [ |
|
| 120 | + $acl[] = [ |
|
| 121 | 121 | 'privilege' => '{DAV:}read', |
| 122 | 122 | 'principal' => parent::getOwner(), |
| 123 | 123 | 'protected' => true, |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | public function delete() { |
| 178 | 178 | if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
| 179 | - $principal = 'principal:' . parent::getOwner(); |
|
| 179 | + $principal = 'principal:'.parent::getOwner(); |
|
| 180 | 180 | $shares = $this->carddavBackend->getShares($this->getResourceId()); |
| 181 | 181 | $shares = array_filter($shares, function($share) use ($principal){ |
| 182 | 182 | return $share['href'] === $principal; |