@@ -94,6 +94,9 @@ |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
| 97 | + /** |
|
| 98 | + * @param integer $circleId |
|
| 99 | + */ |
|
| 97 | 100 | protected function shareToCircle($circleId, array $share) |
| 98 | 101 | { |
| 99 | 102 | if ($circleId < 1) { |
@@ -38,321 +38,321 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
| 40 | 40 | |
| 41 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
| 42 | - parent::__construct($caldavBackend, $calendarInfo); |
|
| 43 | - |
|
| 44 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 45 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 46 | - } |
|
| 47 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 48 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 49 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Updates the list of shares. |
|
| 55 | - * |
|
| 56 | - * The first array is a list of people that are to be added to the |
|
| 57 | - * resource. |
|
| 58 | - * |
|
| 59 | - * Every element in the add array has the following properties: |
|
| 60 | - * * href - A url. Usually a mailto: address |
|
| 61 | - * * commonName - Usually a first and last name, or false |
|
| 62 | - * * summary - A description of the share, can also be false |
|
| 63 | - * * readOnly - A boolean value |
|
| 64 | - * |
|
| 65 | - * Every element in the remove array is just the address string. |
|
| 66 | - * |
|
| 67 | - * @param array $add |
|
| 68 | - * @param array $remove |
|
| 69 | - * @return void |
|
| 70 | - * @throws Forbidden |
|
| 71 | - */ |
|
| 72 | - public function updateShares(array $add, array $remove) { |
|
| 73 | - if ($this->isShared()) { |
|
| 74 | - throw new Forbidden(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $this->updateCircleShares($add, $remove); |
|
| 78 | - $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - protected function updateCircleShares(array &$add, array &$remove) { |
|
| 83 | - |
|
| 84 | - $toAdd = []; |
|
| 85 | - foreach ($add as $added) { |
|
| 86 | - if (substr($added['href'], 0, 29) === 'principal:principals/circles/') { |
|
| 87 | - $circleId = intval(substr($added['href'], 29)); |
|
| 88 | - $this->shareToCircle($circleId, ['calendar' => $this->calendarInfo, 'add' => $added]); |
|
| 89 | - } else { |
|
| 90 | - $toAdd[] = $added; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $add = $toAdd; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - protected function shareToCircle($circleId, array $share) |
|
| 98 | - { |
|
| 99 | - if ($circleId < 1) { |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - \OCA\Circles\Api\v1\Circles::shareToCircle($circleId, 'calendar', 'caldav', $share, '\OCA\DAV\Circles\Broadcaster'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - protected function unshareToCircle($circleId, array $share) |
|
| 108 | - { |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Returns the list of people whom this resource is shared with. |
|
| 115 | - * |
|
| 116 | - * Every element in this array should have the following properties: |
|
| 117 | - * * href - Often a mailto: address |
|
| 118 | - * * commonName - Optional, for example a first + last name |
|
| 119 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 120 | - * * readOnly - boolean |
|
| 121 | - * * summary - Optional, a description for the share |
|
| 122 | - * |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - public function getShares() { |
|
| 126 | - if ($this->isShared()) { |
|
| 127 | - return []; |
|
| 128 | - } |
|
| 129 | - return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function getResourceId() { |
|
| 136 | - return $this->calendarInfo['id']; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function getPrincipalURI() { |
|
| 143 | - return $this->calendarInfo['principaluri']; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - public function getACL() { |
|
| 147 | - $acl = [ |
|
| 148 | - [ |
|
| 149 | - 'privilege' => '{DAV:}read', |
|
| 150 | - 'principal' => $this->getOwner(), |
|
| 151 | - 'protected' => true, |
|
| 152 | - ]]; |
|
| 153 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 154 | - $acl[] = [ |
|
| 155 | - 'privilege' => '{DAV:}write', |
|
| 156 | - 'principal' => $this->getOwner(), |
|
| 157 | - 'protected' => true, |
|
| 158 | - ]; |
|
| 159 | - } else { |
|
| 160 | - $acl[] = [ |
|
| 161 | - 'privilege' => '{DAV:}write-properties', |
|
| 162 | - 'principal' => $this->getOwner(), |
|
| 163 | - 'protected' => true, |
|
| 164 | - ]; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - if ($this->getOwner() !== parent::getOwner()) { |
|
| 168 | - $acl[] = [ |
|
| 169 | - 'privilege' => '{DAV:}read', |
|
| 170 | - 'principal' => parent::getOwner(), |
|
| 171 | - 'protected' => true, |
|
| 172 | - ]; |
|
| 173 | - if ($this->canWrite()) { |
|
| 174 | - $acl[] = [ |
|
| 175 | - 'privilege' => '{DAV:}write', |
|
| 176 | - 'principal' => parent::getOwner(), |
|
| 177 | - 'protected' => true, |
|
| 178 | - ]; |
|
| 179 | - } else { |
|
| 180 | - $acl[] = [ |
|
| 181 | - 'privilege' => '{DAV:}write-properties', |
|
| 182 | - 'principal' => parent::getOwner(), |
|
| 183 | - 'protected' => true, |
|
| 184 | - ]; |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - if ($this->isPublic()) { |
|
| 188 | - $acl[] = [ |
|
| 189 | - 'privilege' => '{DAV:}read', |
|
| 190 | - 'principal' => 'principals/system/public', |
|
| 191 | - 'protected' => true, |
|
| 192 | - ]; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 196 | - |
|
| 197 | - if (!$this->isShared()) { |
|
| 198 | - return $acl; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
| 202 | - return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 203 | - return in_array($rule['principal'], $allowedPrincipals); |
|
| 204 | - }); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - public function getChildACL() { |
|
| 208 | - return $this->getACL(); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - public function getOwner() { |
|
| 212 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 213 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 214 | - } |
|
| 215 | - return parent::getOwner(); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function delete() { |
|
| 219 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 220 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 221 | - $principal = 'principal:' . parent::getOwner(); |
|
| 222 | - $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 223 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
| 224 | - return $share['href'] === $principal; |
|
| 225 | - }); |
|
| 226 | - if (empty($shares)) { |
|
| 227 | - throw new Forbidden(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $this->caldavBackend->updateShares($this, [], [ |
|
| 231 | - 'href' => $principal |
|
| 232 | - ]); |
|
| 233 | - return; |
|
| 234 | - } |
|
| 235 | - parent::delete(); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - public function propPatch(PropPatch $propPatch) { |
|
| 239 | - // parent::propPatch will only update calendars table |
|
| 240 | - // if calendar is shared, changes have to be made to the properties table |
|
| 241 | - if (!$this->isShared()) { |
|
| 242 | - parent::propPatch($propPatch); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - public function getChild($name) { |
|
| 247 | - |
|
| 248 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 249 | - |
|
| 250 | - if (!$obj) { |
|
| 251 | - throw new NotFound('Calendar object not found'); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 255 | - throw new NotFound('Calendar object not found'); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - $obj['acl'] = $this->getChildACL(); |
|
| 259 | - |
|
| 260 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 261 | - |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function getChildren() { |
|
| 265 | - |
|
| 266 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 267 | - $children = []; |
|
| 268 | - foreach ($objs as $obj) { |
|
| 269 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 270 | - continue; |
|
| 271 | - } |
|
| 272 | - $obj['acl'] = $this->getChildACL(); |
|
| 273 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 274 | - } |
|
| 275 | - return $children; |
|
| 276 | - |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - public function getMultipleChildren(array $paths) { |
|
| 280 | - |
|
| 281 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 282 | - $children = []; |
|
| 283 | - foreach ($objs as $obj) { |
|
| 284 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 285 | - continue; |
|
| 286 | - } |
|
| 287 | - $obj['acl'] = $this->getChildACL(); |
|
| 288 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 289 | - } |
|
| 290 | - return $children; |
|
| 291 | - |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - public function childExists($name) { |
|
| 295 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 296 | - if (!$obj) { |
|
| 297 | - return false; |
|
| 298 | - } |
|
| 299 | - if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 300 | - return false; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - return true; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - public function calendarQuery(array $filters) { |
|
| 307 | - |
|
| 308 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 309 | - if ($this->isShared()) { |
|
| 310 | - return array_filter($uris, function ($uri) { |
|
| 311 | - return $this->childExists($uri); |
|
| 312 | - }); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - return $uris; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @param boolean $value |
|
| 320 | - * @return string|null |
|
| 321 | - */ |
|
| 322 | - public function setPublishStatus($value) { |
|
| 323 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 324 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
| 325 | - return $publicUri; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @return mixed $value |
|
| 330 | - */ |
|
| 331 | - public function getPublishStatus() { |
|
| 332 | - return $this->caldavBackend->getPublishStatus($this); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - private function canWrite() { |
|
| 336 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 337 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 338 | - } |
|
| 339 | - return true; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - private function isPublic() { |
|
| 343 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - protected function isShared() { |
|
| 347 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 348 | - return false; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - public function isSubscription() { |
|
| 355 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 356 | - } |
|
| 41 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
| 42 | + parent::__construct($caldavBackend, $calendarInfo); |
|
| 43 | + |
|
| 44 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 45 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
| 46 | + } |
|
| 47 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
| 48 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
| 49 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Updates the list of shares. |
|
| 55 | + * |
|
| 56 | + * The first array is a list of people that are to be added to the |
|
| 57 | + * resource. |
|
| 58 | + * |
|
| 59 | + * Every element in the add array has the following properties: |
|
| 60 | + * * href - A url. Usually a mailto: address |
|
| 61 | + * * commonName - Usually a first and last name, or false |
|
| 62 | + * * summary - A description of the share, can also be false |
|
| 63 | + * * readOnly - A boolean value |
|
| 64 | + * |
|
| 65 | + * Every element in the remove array is just the address string. |
|
| 66 | + * |
|
| 67 | + * @param array $add |
|
| 68 | + * @param array $remove |
|
| 69 | + * @return void |
|
| 70 | + * @throws Forbidden |
|
| 71 | + */ |
|
| 72 | + public function updateShares(array $add, array $remove) { |
|
| 73 | + if ($this->isShared()) { |
|
| 74 | + throw new Forbidden(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $this->updateCircleShares($add, $remove); |
|
| 78 | + $this->caldavBackend->updateShares($this, $add, $remove); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + protected function updateCircleShares(array &$add, array &$remove) { |
|
| 83 | + |
|
| 84 | + $toAdd = []; |
|
| 85 | + foreach ($add as $added) { |
|
| 86 | + if (substr($added['href'], 0, 29) === 'principal:principals/circles/') { |
|
| 87 | + $circleId = intval(substr($added['href'], 29)); |
|
| 88 | + $this->shareToCircle($circleId, ['calendar' => $this->calendarInfo, 'add' => $added]); |
|
| 89 | + } else { |
|
| 90 | + $toAdd[] = $added; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $add = $toAdd; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + protected function shareToCircle($circleId, array $share) |
|
| 98 | + { |
|
| 99 | + if ($circleId < 1) { |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + \OCA\Circles\Api\v1\Circles::shareToCircle($circleId, 'calendar', 'caldav', $share, '\OCA\DAV\Circles\Broadcaster'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + protected function unshareToCircle($circleId, array $share) |
|
| 108 | + { |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Returns the list of people whom this resource is shared with. |
|
| 115 | + * |
|
| 116 | + * Every element in this array should have the following properties: |
|
| 117 | + * * href - Often a mailto: address |
|
| 118 | + * * commonName - Optional, for example a first + last name |
|
| 119 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
| 120 | + * * readOnly - boolean |
|
| 121 | + * * summary - Optional, a description for the share |
|
| 122 | + * |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + public function getShares() { |
|
| 126 | + if ($this->isShared()) { |
|
| 127 | + return []; |
|
| 128 | + } |
|
| 129 | + return $this->caldavBackend->getShares($this->getResourceId()); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function getResourceId() { |
|
| 136 | + return $this->calendarInfo['id']; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function getPrincipalURI() { |
|
| 143 | + return $this->calendarInfo['principaluri']; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + public function getACL() { |
|
| 147 | + $acl = [ |
|
| 148 | + [ |
|
| 149 | + 'privilege' => '{DAV:}read', |
|
| 150 | + 'principal' => $this->getOwner(), |
|
| 151 | + 'protected' => true, |
|
| 152 | + ]]; |
|
| 153 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
| 154 | + $acl[] = [ |
|
| 155 | + 'privilege' => '{DAV:}write', |
|
| 156 | + 'principal' => $this->getOwner(), |
|
| 157 | + 'protected' => true, |
|
| 158 | + ]; |
|
| 159 | + } else { |
|
| 160 | + $acl[] = [ |
|
| 161 | + 'privilege' => '{DAV:}write-properties', |
|
| 162 | + 'principal' => $this->getOwner(), |
|
| 163 | + 'protected' => true, |
|
| 164 | + ]; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + if ($this->getOwner() !== parent::getOwner()) { |
|
| 168 | + $acl[] = [ |
|
| 169 | + 'privilege' => '{DAV:}read', |
|
| 170 | + 'principal' => parent::getOwner(), |
|
| 171 | + 'protected' => true, |
|
| 172 | + ]; |
|
| 173 | + if ($this->canWrite()) { |
|
| 174 | + $acl[] = [ |
|
| 175 | + 'privilege' => '{DAV:}write', |
|
| 176 | + 'principal' => parent::getOwner(), |
|
| 177 | + 'protected' => true, |
|
| 178 | + ]; |
|
| 179 | + } else { |
|
| 180 | + $acl[] = [ |
|
| 181 | + 'privilege' => '{DAV:}write-properties', |
|
| 182 | + 'principal' => parent::getOwner(), |
|
| 183 | + 'protected' => true, |
|
| 184 | + ]; |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + if ($this->isPublic()) { |
|
| 188 | + $acl[] = [ |
|
| 189 | + 'privilege' => '{DAV:}read', |
|
| 190 | + 'principal' => 'principals/system/public', |
|
| 191 | + 'protected' => true, |
|
| 192 | + ]; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $acl = $this->caldavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
| 196 | + |
|
| 197 | + if (!$this->isShared()) { |
|
| 198 | + return $acl; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $allowedPrincipals = [$this->getOwner(), parent::getOwner(), 'principals/system/public']; |
|
| 202 | + return array_filter($acl, function($rule) use ($allowedPrincipals) { |
|
| 203 | + return in_array($rule['principal'], $allowedPrincipals); |
|
| 204 | + }); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + public function getChildACL() { |
|
| 208 | + return $this->getACL(); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + public function getOwner() { |
|
| 212 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 213 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
| 214 | + } |
|
| 215 | + return parent::getOwner(); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + public function delete() { |
|
| 219 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
| 220 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
| 221 | + $principal = 'principal:' . parent::getOwner(); |
|
| 222 | + $shares = $this->caldavBackend->getShares($this->getResourceId()); |
|
| 223 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
| 224 | + return $share['href'] === $principal; |
|
| 225 | + }); |
|
| 226 | + if (empty($shares)) { |
|
| 227 | + throw new Forbidden(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $this->caldavBackend->updateShares($this, [], [ |
|
| 231 | + 'href' => $principal |
|
| 232 | + ]); |
|
| 233 | + return; |
|
| 234 | + } |
|
| 235 | + parent::delete(); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + public function propPatch(PropPatch $propPatch) { |
|
| 239 | + // parent::propPatch will only update calendars table |
|
| 240 | + // if calendar is shared, changes have to be made to the properties table |
|
| 241 | + if (!$this->isShared()) { |
|
| 242 | + parent::propPatch($propPatch); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + public function getChild($name) { |
|
| 247 | + |
|
| 248 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 249 | + |
|
| 250 | + if (!$obj) { |
|
| 251 | + throw new NotFound('Calendar object not found'); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 255 | + throw new NotFound('Calendar object not found'); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + $obj['acl'] = $this->getChildACL(); |
|
| 259 | + |
|
| 260 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 261 | + |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function getChildren() { |
|
| 265 | + |
|
| 266 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
| 267 | + $children = []; |
|
| 268 | + foreach ($objs as $obj) { |
|
| 269 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 270 | + continue; |
|
| 271 | + } |
|
| 272 | + $obj['acl'] = $this->getChildACL(); |
|
| 273 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 274 | + } |
|
| 275 | + return $children; |
|
| 276 | + |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + public function getMultipleChildren(array $paths) { |
|
| 280 | + |
|
| 281 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
| 282 | + $children = []; |
|
| 283 | + foreach ($objs as $obj) { |
|
| 284 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 287 | + $obj['acl'] = $this->getChildACL(); |
|
| 288 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
| 289 | + } |
|
| 290 | + return $children; |
|
| 291 | + |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + public function childExists($name) { |
|
| 295 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
| 296 | + if (!$obj) { |
|
| 297 | + return false; |
|
| 298 | + } |
|
| 299 | + if ($obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE && $this->isShared()) { |
|
| 300 | + return false; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + return true; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + public function calendarQuery(array $filters) { |
|
| 307 | + |
|
| 308 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
| 309 | + if ($this->isShared()) { |
|
| 310 | + return array_filter($uris, function ($uri) { |
|
| 311 | + return $this->childExists($uri); |
|
| 312 | + }); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + return $uris; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @param boolean $value |
|
| 320 | + * @return string|null |
|
| 321 | + */ |
|
| 322 | + public function setPublishStatus($value) { |
|
| 323 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
| 324 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
| 325 | + return $publicUri; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @return mixed $value |
|
| 330 | + */ |
|
| 331 | + public function getPublishStatus() { |
|
| 332 | + return $this->caldavBackend->getPublishStatus($this); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + private function canWrite() { |
|
| 336 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
| 337 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
| 338 | + } |
|
| 339 | + return true; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + private function isPublic() { |
|
| 343 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + protected function isShared() { |
|
| 347 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + public function isSubscription() { |
|
| 355 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | 358 | } |
@@ -150,7 +150,6 @@ |
||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | - * @param IGroup $group |
|
| 154 | 153 | * @return array |
| 155 | 154 | */ |
| 156 | 155 | protected function circleToPrincipal($circle) { |
@@ -10,170 +10,170 @@ |
||
| 10 | 10 | |
| 11 | 11 | class CirclePrincipalBackend implements BackendInterface { |
| 12 | 12 | |
| 13 | - const PRINCIPAL_PREFIX = 'principals/circles'; |
|
| 14 | - |
|
| 15 | - public function __construct() { |
|
| 16 | - |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Returns a list of principals based on a prefix. |
|
| 21 | - * |
|
| 22 | - * This prefix will often contain something like 'principals'. You are only |
|
| 23 | - * expected to return principals that are in this base path. |
|
| 24 | - * |
|
| 25 | - * You are expected to return at least a 'uri' for every user, you can |
|
| 26 | - * return any additional properties if you wish so. Common properties are: |
|
| 27 | - * {DAV:}displayname |
|
| 28 | - * |
|
| 29 | - * @param string $prefixPath |
|
| 30 | - * @return string[] |
|
| 31 | - */ |
|
| 32 | - public function getPrincipalsByPrefix($prefixPath) { |
|
| 33 | - $principals = []; |
|
| 34 | - |
|
| 35 | - if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
| 36 | - foreach(\OCA\Circles\Api\v1\Circles::joinedCircles() as $circle) |
|
| 37 | - { |
|
| 38 | - \OC::$server->getLogger()->log(2, 'CIRCLE: ' . $circle->getName()); |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return $principals; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Returns a specific principal, specified by it's path. |
|
| 47 | - * The returned structure should be the exact same as from |
|
| 48 | - * getPrincipalsByPrefix. |
|
| 49 | - * |
|
| 50 | - * @param string $path |
|
| 51 | - * @return array |
|
| 52 | - */ |
|
| 53 | - public function getPrincipalByPath($path) { |
|
| 54 | - |
|
| 55 | - $elements = explode('/', $path, 3); |
|
| 56 | - if ($elements[0] !== 'principals') { |
|
| 57 | - return null; |
|
| 58 | - } |
|
| 59 | - if ($elements[1] !== 'circles') { |
|
| 60 | - return null; |
|
| 61 | - } |
|
| 62 | - $circleId = intval(urldecode($elements[2])); |
|
| 63 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId); |
|
| 64 | - |
|
| 65 | - if (!is_null($circle)) { |
|
| 66 | - return $this->circleToPrincipal($circle); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return null; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Returns the list of members for a group-principal |
|
| 74 | - * |
|
| 75 | - * @param string $principal |
|
| 76 | - * @return string[] |
|
| 77 | - * @throws Exception |
|
| 78 | - */ |
|
| 79 | - public function getGroupMemberSet($principal) { |
|
| 80 | - |
|
| 81 | - $elements = explode('/', $principal); |
|
| 82 | - if ($elements[0] !== 'principals') { |
|
| 83 | - return []; |
|
| 84 | - } |
|
| 85 | - if ($elements[1] !== 'groups') { |
|
| 86 | - return []; |
|
| 87 | - } |
|
| 88 | - $name = $elements[2]; |
|
| 89 | - $group = $this->groupManager->get($name); |
|
| 90 | - |
|
| 91 | - if (is_null($group)) { |
|
| 92 | - return []; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return array_map(function($user) { |
|
| 96 | - return $this->userToPrincipal($user); |
|
| 97 | - }, $group->getUsers()); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns the list of groups a principal is a member of |
|
| 102 | - * |
|
| 103 | - * @param string $principal |
|
| 104 | - * @return array |
|
| 105 | - * @throws Exception |
|
| 106 | - */ |
|
| 107 | - public function getGroupMembership($principal) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Updates the list of group members for a group principal. |
|
| 113 | - * |
|
| 114 | - * The principals should be passed as a list of uri's. |
|
| 115 | - * |
|
| 116 | - * @param string $principal |
|
| 117 | - * @param string[] $members |
|
| 118 | - * @throws Exception |
|
| 119 | - */ |
|
| 120 | - public function setGroupMemberSet($principal, array $members) { |
|
| 121 | - throw new Exception('Setting members of the group is not supported yet'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param string $path |
|
| 126 | - * @param PropPatch $propPatch |
|
| 127 | - * @return int |
|
| 128 | - */ |
|
| 129 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
| 130 | - return 0; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param string $prefixPath |
|
| 135 | - * @param array $searchProperties |
|
| 136 | - * @param string $test |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 140 | - return []; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @param string $uri |
|
| 145 | - * @param string $principalPrefix |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - function findByUri($uri, $principalPrefix) { |
|
| 149 | - return ''; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @param IGroup $group |
|
| 154 | - * @return array |
|
| 155 | - */ |
|
| 156 | - protected function circleToPrincipal($circle) { |
|
| 157 | - |
|
| 158 | - $principal = [ |
|
| 159 | - 'uri' => 'principals/circles/' . $circle->getId(), |
|
| 160 | - '{DAV:}displayname' => $circle->getName(), |
|
| 161 | - ]; |
|
| 162 | - |
|
| 163 | - return $principal; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param IUser $user |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 170 | - protected function userToPrincipal($user) { |
|
| 171 | - |
|
| 172 | - $principal = [ |
|
| 173 | - 'uri' => 'principals/users/' . $user->getUID(), |
|
| 174 | - '{DAV:}displayname' => $user->getDisplayName(), |
|
| 175 | - ]; |
|
| 176 | - |
|
| 177 | - return $principal; |
|
| 178 | - } |
|
| 13 | + const PRINCIPAL_PREFIX = 'principals/circles'; |
|
| 14 | + |
|
| 15 | + public function __construct() { |
|
| 16 | + |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Returns a list of principals based on a prefix. |
|
| 21 | + * |
|
| 22 | + * This prefix will often contain something like 'principals'. You are only |
|
| 23 | + * expected to return principals that are in this base path. |
|
| 24 | + * |
|
| 25 | + * You are expected to return at least a 'uri' for every user, you can |
|
| 26 | + * return any additional properties if you wish so. Common properties are: |
|
| 27 | + * {DAV:}displayname |
|
| 28 | + * |
|
| 29 | + * @param string $prefixPath |
|
| 30 | + * @return string[] |
|
| 31 | + */ |
|
| 32 | + public function getPrincipalsByPrefix($prefixPath) { |
|
| 33 | + $principals = []; |
|
| 34 | + |
|
| 35 | + if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
| 36 | + foreach(\OCA\Circles\Api\v1\Circles::joinedCircles() as $circle) |
|
| 37 | + { |
|
| 38 | + \OC::$server->getLogger()->log(2, 'CIRCLE: ' . $circle->getName()); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return $principals; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Returns a specific principal, specified by it's path. |
|
| 47 | + * The returned structure should be the exact same as from |
|
| 48 | + * getPrincipalsByPrefix. |
|
| 49 | + * |
|
| 50 | + * @param string $path |
|
| 51 | + * @return array |
|
| 52 | + */ |
|
| 53 | + public function getPrincipalByPath($path) { |
|
| 54 | + |
|
| 55 | + $elements = explode('/', $path, 3); |
|
| 56 | + if ($elements[0] !== 'principals') { |
|
| 57 | + return null; |
|
| 58 | + } |
|
| 59 | + if ($elements[1] !== 'circles') { |
|
| 60 | + return null; |
|
| 61 | + } |
|
| 62 | + $circleId = intval(urldecode($elements[2])); |
|
| 63 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($circleId); |
|
| 64 | + |
|
| 65 | + if (!is_null($circle)) { |
|
| 66 | + return $this->circleToPrincipal($circle); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return null; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Returns the list of members for a group-principal |
|
| 74 | + * |
|
| 75 | + * @param string $principal |
|
| 76 | + * @return string[] |
|
| 77 | + * @throws Exception |
|
| 78 | + */ |
|
| 79 | + public function getGroupMemberSet($principal) { |
|
| 80 | + |
|
| 81 | + $elements = explode('/', $principal); |
|
| 82 | + if ($elements[0] !== 'principals') { |
|
| 83 | + return []; |
|
| 84 | + } |
|
| 85 | + if ($elements[1] !== 'groups') { |
|
| 86 | + return []; |
|
| 87 | + } |
|
| 88 | + $name = $elements[2]; |
|
| 89 | + $group = $this->groupManager->get($name); |
|
| 90 | + |
|
| 91 | + if (is_null($group)) { |
|
| 92 | + return []; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return array_map(function($user) { |
|
| 96 | + return $this->userToPrincipal($user); |
|
| 97 | + }, $group->getUsers()); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns the list of groups a principal is a member of |
|
| 102 | + * |
|
| 103 | + * @param string $principal |
|
| 104 | + * @return array |
|
| 105 | + * @throws Exception |
|
| 106 | + */ |
|
| 107 | + public function getGroupMembership($principal) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Updates the list of group members for a group principal. |
|
| 113 | + * |
|
| 114 | + * The principals should be passed as a list of uri's. |
|
| 115 | + * |
|
| 116 | + * @param string $principal |
|
| 117 | + * @param string[] $members |
|
| 118 | + * @throws Exception |
|
| 119 | + */ |
|
| 120 | + public function setGroupMemberSet($principal, array $members) { |
|
| 121 | + throw new Exception('Setting members of the group is not supported yet'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $path |
|
| 126 | + * @param PropPatch $propPatch |
|
| 127 | + * @return int |
|
| 128 | + */ |
|
| 129 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
| 130 | + return 0; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param string $prefixPath |
|
| 135 | + * @param array $searchProperties |
|
| 136 | + * @param string $test |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 140 | + return []; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @param string $uri |
|
| 145 | + * @param string $principalPrefix |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + function findByUri($uri, $principalPrefix) { |
|
| 149 | + return ''; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @param IGroup $group |
|
| 154 | + * @return array |
|
| 155 | + */ |
|
| 156 | + protected function circleToPrincipal($circle) { |
|
| 157 | + |
|
| 158 | + $principal = [ |
|
| 159 | + 'uri' => 'principals/circles/' . $circle->getId(), |
|
| 160 | + '{DAV:}displayname' => $circle->getName(), |
|
| 161 | + ]; |
|
| 162 | + |
|
| 163 | + return $principal; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param IUser $user |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | + protected function userToPrincipal($user) { |
|
| 171 | + |
|
| 172 | + $principal = [ |
|
| 173 | + 'uri' => 'principals/users/' . $user->getUID(), |
|
| 174 | + '{DAV:}displayname' => $user->getDisplayName(), |
|
| 175 | + ]; |
|
| 176 | + |
|
| 177 | + return $principal; |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | $principals = []; |
| 34 | 34 | |
| 35 | 35 | if ($prefixPath === self::PRINCIPAL_PREFIX) { |
| 36 | - foreach(\OCA\Circles\Api\v1\Circles::joinedCircles() as $circle) |
|
| 36 | + foreach (\OCA\Circles\Api\v1\Circles::joinedCircles() as $circle) |
|
| 37 | 37 | { |
| 38 | - \OC::$server->getLogger()->log(2, 'CIRCLE: ' . $circle->getName()); |
|
| 38 | + \OC::$server->getLogger()->log(2, 'CIRCLE: '.$circle->getName()); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function getPrincipalByPath($path) { |
| 54 | 54 | |
| 55 | - $elements = explode('/', $path, 3); |
|
| 55 | + $elements = explode('/', $path, 3); |
|
| 56 | 56 | if ($elements[0] !== 'principals') { |
| 57 | 57 | return null; |
| 58 | 58 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | protected function circleToPrincipal($circle) { |
| 157 | 157 | |
| 158 | 158 | $principal = [ |
| 159 | - 'uri' => 'principals/circles/' . $circle->getId(), |
|
| 159 | + 'uri' => 'principals/circles/'.$circle->getId(), |
|
| 160 | 160 | '{DAV:}displayname' => $circle->getName(), |
| 161 | 161 | ]; |
| 162 | 162 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | protected function userToPrincipal($user) { |
| 171 | 171 | |
| 172 | 172 | $principal = [ |
| 173 | - 'uri' => 'principals/users/' . $user->getUID(), |
|
| 173 | + 'uri' => 'principals/users/'.$user->getUID(), |
|
| 174 | 174 | '{DAV:}displayname' => $user->getDisplayName(), |
| 175 | 175 | ]; |
| 176 | 176 | |
@@ -58,198 +58,198 @@ |
||
| 58 | 58 | |
| 59 | 59 | class Server { |
| 60 | 60 | |
| 61 | - /** @var IRequest */ |
|
| 62 | - private $request; |
|
| 63 | - |
|
| 64 | - /** @var string */ |
|
| 65 | - private $baseUri; |
|
| 66 | - |
|
| 67 | - /** @var Connector\Sabre\Server */ |
|
| 68 | - private $server; |
|
| 69 | - |
|
| 70 | - public function __construct(IRequest $request, $baseUri) { |
|
| 71 | - $this->request = $request; |
|
| 72 | - $this->baseUri = $baseUri; |
|
| 73 | - $logger = \OC::$server->getLogger(); |
|
| 74 | - $mailer = \OC::$server->getMailer(); |
|
| 75 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 76 | - |
|
| 77 | - $root = new RootCollection(); |
|
| 78 | - $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 79 | - |
|
| 80 | - // Add maintenance plugin |
|
| 81 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 82 | - |
|
| 83 | - // Backends |
|
| 84 | - $authBackend = new Auth( |
|
| 85 | - \OC::$server->getSession(), |
|
| 86 | - \OC::$server->getUserSession(), |
|
| 87 | - \OC::$server->getRequest(), |
|
| 88 | - \OC::$server->getTwoFactorAuthManager(), |
|
| 89 | - \OC::$server->getBruteForceThrottler() |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - // Set URL explicitly due to reverse-proxy situations |
|
| 93 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 94 | - $this->server->setBaseUri($this->baseUri); |
|
| 95 | - |
|
| 96 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 97 | - $authPlugin = new Plugin(); |
|
| 98 | - $authPlugin->addBackend(new PublicAuth()); |
|
| 99 | - $this->server->addPlugin($authPlugin); |
|
| 100 | - |
|
| 101 | - // allow setup of additional auth backends |
|
| 102 | - $event = new SabrePluginEvent($this->server); |
|
| 103 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 104 | - |
|
| 105 | - $bearerAuthBackend = new BearerAuth( |
|
| 106 | - \OC::$server->getUserSession(), |
|
| 107 | - \OC::$server->getSession(), |
|
| 108 | - \OC::$server->getRequest() |
|
| 109 | - ); |
|
| 110 | - $authPlugin->addBackend($bearerAuthBackend); |
|
| 111 | - // because we are throwing exceptions this plugin has to be the last one |
|
| 112 | - $authPlugin->addBackend($authBackend); |
|
| 113 | - |
|
| 114 | - // debugging |
|
| 115 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 116 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 117 | - } else { |
|
| 118 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 122 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 123 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 124 | - |
|
| 125 | - // acl |
|
| 126 | - $acl = new DavAclPlugin(); |
|
| 127 | - $acl->principalCollectionSet = [ |
|
| 128 | - 'principals/users', 'principals/groups', 'principals/circles' |
|
| 129 | - ]; |
|
| 130 | - $acl->defaultUsernamePath = 'principals/users'; |
|
| 131 | - $this->server->addPlugin($acl); |
|
| 132 | - |
|
| 133 | - // calendar plugins |
|
| 134 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 135 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 136 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 137 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 138 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 139 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 140 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 141 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 142 | - \OC::$server->getConfig(), |
|
| 143 | - \OC::$server->getURLGenerator() |
|
| 144 | - )); |
|
| 145 | - |
|
| 146 | - // addressbook plugins |
|
| 147 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 148 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
| 149 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 150 | - |
|
| 151 | - // system tags plugins |
|
| 152 | - $this->server->addPlugin(new SystemTagPlugin( |
|
| 153 | - \OC::$server->getSystemTagManager(), |
|
| 154 | - \OC::$server->getGroupManager(), |
|
| 155 | - \OC::$server->getUserSession() |
|
| 156 | - )); |
|
| 157 | - |
|
| 158 | - // comments plugin |
|
| 159 | - $this->server->addPlugin(new CommentsPlugin( |
|
| 160 | - \OC::$server->getCommentsManager(), |
|
| 161 | - \OC::$server->getUserSession() |
|
| 162 | - )); |
|
| 163 | - |
|
| 164 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 165 | - |
|
| 166 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 167 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 168 | - if($request->isUserAgent([ |
|
| 169 | - '/WebDAVFS/', |
|
| 170 | - '/Microsoft Office OneNote 2013/', |
|
| 171 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 172 | - ])) { |
|
| 173 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 177 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 181 | - $this->server->on('beforeMethod', function () { |
|
| 182 | - // custom properties plugin must be the last one |
|
| 183 | - $userSession = \OC::$server->getUserSession(); |
|
| 184 | - $user = $userSession->getUser(); |
|
| 185 | - if ($user !== null) { |
|
| 186 | - $view = \OC\Files\Filesystem::getView(); |
|
| 187 | - $this->server->addPlugin( |
|
| 188 | - new FilesPlugin( |
|
| 189 | - $this->server->tree, |
|
| 190 | - \OC::$server->getConfig(), |
|
| 191 | - $this->request, |
|
| 192 | - \OC::$server->getPreviewManager(), |
|
| 193 | - false, |
|
| 194 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 195 | - ) |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - $this->server->addPlugin( |
|
| 199 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 200 | - new CustomPropertiesBackend( |
|
| 201 | - $this->server->tree, |
|
| 202 | - \OC::$server->getDatabaseConnection(), |
|
| 203 | - \OC::$server->getUserSession()->getUser() |
|
| 204 | - ) |
|
| 205 | - ) |
|
| 206 | - ); |
|
| 207 | - if ($view !== null) { |
|
| 208 | - $this->server->addPlugin( |
|
| 209 | - new QuotaPlugin($view)); |
|
| 210 | - } |
|
| 211 | - $this->server->addPlugin( |
|
| 212 | - new TagsPlugin( |
|
| 213 | - $this->server->tree, \OC::$server->getTagManager() |
|
| 214 | - ) |
|
| 215 | - ); |
|
| 216 | - // TODO: switch to LazyUserFolder |
|
| 217 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 218 | - $this->server->addPlugin(new SharesPlugin( |
|
| 219 | - $this->server->tree, |
|
| 220 | - $userSession, |
|
| 221 | - $userFolder, |
|
| 222 | - \OC::$server->getShareManager() |
|
| 223 | - )); |
|
| 224 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 225 | - \OC::$server->getCommentsManager(), |
|
| 226 | - $userSession |
|
| 227 | - )); |
|
| 228 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 229 | - if ($view !== null) { |
|
| 230 | - $this->server->addPlugin(new FilesReportPlugin( |
|
| 231 | - $this->server->tree, |
|
| 232 | - $view, |
|
| 233 | - \OC::$server->getSystemTagManager(), |
|
| 234 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 235 | - \OC::$server->getTagManager(), |
|
| 236 | - $userSession, |
|
| 237 | - \OC::$server->getGroupManager(), |
|
| 238 | - $userFolder |
|
| 239 | - )); |
|
| 240 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 241 | - $this->server->tree, |
|
| 242 | - $user, |
|
| 243 | - \OC::$server->getRootFolder(), |
|
| 244 | - \OC::$server->getShareManager(), |
|
| 245 | - $view |
|
| 246 | - ))); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - }); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - public function exec() { |
|
| 253 | - $this->server->exec(); |
|
| 254 | - } |
|
| 61 | + /** @var IRequest */ |
|
| 62 | + private $request; |
|
| 63 | + |
|
| 64 | + /** @var string */ |
|
| 65 | + private $baseUri; |
|
| 66 | + |
|
| 67 | + /** @var Connector\Sabre\Server */ |
|
| 68 | + private $server; |
|
| 69 | + |
|
| 70 | + public function __construct(IRequest $request, $baseUri) { |
|
| 71 | + $this->request = $request; |
|
| 72 | + $this->baseUri = $baseUri; |
|
| 73 | + $logger = \OC::$server->getLogger(); |
|
| 74 | + $mailer = \OC::$server->getMailer(); |
|
| 75 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 76 | + |
|
| 77 | + $root = new RootCollection(); |
|
| 78 | + $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
| 79 | + |
|
| 80 | + // Add maintenance plugin |
|
| 81 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
| 82 | + |
|
| 83 | + // Backends |
|
| 84 | + $authBackend = new Auth( |
|
| 85 | + \OC::$server->getSession(), |
|
| 86 | + \OC::$server->getUserSession(), |
|
| 87 | + \OC::$server->getRequest(), |
|
| 88 | + \OC::$server->getTwoFactorAuthManager(), |
|
| 89 | + \OC::$server->getBruteForceThrottler() |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + // Set URL explicitly due to reverse-proxy situations |
|
| 93 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
| 94 | + $this->server->setBaseUri($this->baseUri); |
|
| 95 | + |
|
| 96 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
| 97 | + $authPlugin = new Plugin(); |
|
| 98 | + $authPlugin->addBackend(new PublicAuth()); |
|
| 99 | + $this->server->addPlugin($authPlugin); |
|
| 100 | + |
|
| 101 | + // allow setup of additional auth backends |
|
| 102 | + $event = new SabrePluginEvent($this->server); |
|
| 103 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
| 104 | + |
|
| 105 | + $bearerAuthBackend = new BearerAuth( |
|
| 106 | + \OC::$server->getUserSession(), |
|
| 107 | + \OC::$server->getSession(), |
|
| 108 | + \OC::$server->getRequest() |
|
| 109 | + ); |
|
| 110 | + $authPlugin->addBackend($bearerAuthBackend); |
|
| 111 | + // because we are throwing exceptions this plugin has to be the last one |
|
| 112 | + $authPlugin->addBackend($authBackend); |
|
| 113 | + |
|
| 114 | + // debugging |
|
| 115 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
| 116 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
| 117 | + } else { |
|
| 118 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
| 122 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 123 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
| 124 | + |
|
| 125 | + // acl |
|
| 126 | + $acl = new DavAclPlugin(); |
|
| 127 | + $acl->principalCollectionSet = [ |
|
| 128 | + 'principals/users', 'principals/groups', 'principals/circles' |
|
| 129 | + ]; |
|
| 130 | + $acl->defaultUsernamePath = 'principals/users'; |
|
| 131 | + $this->server->addPlugin($acl); |
|
| 132 | + |
|
| 133 | + // calendar plugins |
|
| 134 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
| 135 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
| 136 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
| 137 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
| 138 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
| 139 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
| 140 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
| 141 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
| 142 | + \OC::$server->getConfig(), |
|
| 143 | + \OC::$server->getURLGenerator() |
|
| 144 | + )); |
|
| 145 | + |
|
| 146 | + // addressbook plugins |
|
| 147 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
| 148 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
| 149 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache(\OC::$server->getAppDataDir('dav-photocache')))); |
|
| 150 | + |
|
| 151 | + // system tags plugins |
|
| 152 | + $this->server->addPlugin(new SystemTagPlugin( |
|
| 153 | + \OC::$server->getSystemTagManager(), |
|
| 154 | + \OC::$server->getGroupManager(), |
|
| 155 | + \OC::$server->getUserSession() |
|
| 156 | + )); |
|
| 157 | + |
|
| 158 | + // comments plugin |
|
| 159 | + $this->server->addPlugin(new CommentsPlugin( |
|
| 160 | + \OC::$server->getCommentsManager(), |
|
| 161 | + \OC::$server->getUserSession() |
|
| 162 | + )); |
|
| 163 | + |
|
| 164 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
| 165 | + |
|
| 166 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 167 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 168 | + if($request->isUserAgent([ |
|
| 169 | + '/WebDAVFS/', |
|
| 170 | + '/Microsoft Office OneNote 2013/', |
|
| 171 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
| 172 | + ])) { |
|
| 173 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
| 177 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 181 | + $this->server->on('beforeMethod', function () { |
|
| 182 | + // custom properties plugin must be the last one |
|
| 183 | + $userSession = \OC::$server->getUserSession(); |
|
| 184 | + $user = $userSession->getUser(); |
|
| 185 | + if ($user !== null) { |
|
| 186 | + $view = \OC\Files\Filesystem::getView(); |
|
| 187 | + $this->server->addPlugin( |
|
| 188 | + new FilesPlugin( |
|
| 189 | + $this->server->tree, |
|
| 190 | + \OC::$server->getConfig(), |
|
| 191 | + $this->request, |
|
| 192 | + \OC::$server->getPreviewManager(), |
|
| 193 | + false, |
|
| 194 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
| 195 | + ) |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + $this->server->addPlugin( |
|
| 199 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 200 | + new CustomPropertiesBackend( |
|
| 201 | + $this->server->tree, |
|
| 202 | + \OC::$server->getDatabaseConnection(), |
|
| 203 | + \OC::$server->getUserSession()->getUser() |
|
| 204 | + ) |
|
| 205 | + ) |
|
| 206 | + ); |
|
| 207 | + if ($view !== null) { |
|
| 208 | + $this->server->addPlugin( |
|
| 209 | + new QuotaPlugin($view)); |
|
| 210 | + } |
|
| 211 | + $this->server->addPlugin( |
|
| 212 | + new TagsPlugin( |
|
| 213 | + $this->server->tree, \OC::$server->getTagManager() |
|
| 214 | + ) |
|
| 215 | + ); |
|
| 216 | + // TODO: switch to LazyUserFolder |
|
| 217 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 218 | + $this->server->addPlugin(new SharesPlugin( |
|
| 219 | + $this->server->tree, |
|
| 220 | + $userSession, |
|
| 221 | + $userFolder, |
|
| 222 | + \OC::$server->getShareManager() |
|
| 223 | + )); |
|
| 224 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
| 225 | + \OC::$server->getCommentsManager(), |
|
| 226 | + $userSession |
|
| 227 | + )); |
|
| 228 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
| 229 | + if ($view !== null) { |
|
| 230 | + $this->server->addPlugin(new FilesReportPlugin( |
|
| 231 | + $this->server->tree, |
|
| 232 | + $view, |
|
| 233 | + \OC::$server->getSystemTagManager(), |
|
| 234 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 235 | + \OC::$server->getTagManager(), |
|
| 236 | + $userSession, |
|
| 237 | + \OC::$server->getGroupManager(), |
|
| 238 | + $userFolder |
|
| 239 | + )); |
|
| 240 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
| 241 | + $this->server->tree, |
|
| 242 | + $user, |
|
| 243 | + \OC::$server->getRootFolder(), |
|
| 244 | + \OC::$server->getShareManager(), |
|
| 245 | + $view |
|
| 246 | + ))); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + }); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + public function exec() { |
|
| 253 | + $this->server->exec(); |
|
| 254 | + } |
|
| 255 | 255 | } |
@@ -38,93 +38,93 @@ |
||
| 38 | 38 | |
| 39 | 39 | class RootCollection extends SimpleCollection { |
| 40 | 40 | |
| 41 | - public function __construct() { |
|
| 42 | - $config = \OC::$server->getConfig(); |
|
| 43 | - $random = \OC::$server->getSecureRandom(); |
|
| 44 | - $userManager = \OC::$server->getUserManager(); |
|
| 45 | - $db = \OC::$server->getDatabaseConnection(); |
|
| 46 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 47 | - $userPrincipalBackend = new Principal( |
|
| 48 | - $userManager, |
|
| 49 | - \OC::$server->getGroupManager() |
|
| 50 | - ); |
|
| 51 | - $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 52 | - \OC::$server->getGroupManager() |
|
| 53 | - ); |
|
| 54 | - $circlePrincipalBackend = new CirclePrincipalBackend(); |
|
| 55 | - // as soon as debug mode is enabled we allow listing of principals |
|
| 56 | - $disableListing = !$config->getSystemValue('debug', false); |
|
| 41 | + public function __construct() { |
|
| 42 | + $config = \OC::$server->getConfig(); |
|
| 43 | + $random = \OC::$server->getSecureRandom(); |
|
| 44 | + $userManager = \OC::$server->getUserManager(); |
|
| 45 | + $db = \OC::$server->getDatabaseConnection(); |
|
| 46 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
| 47 | + $userPrincipalBackend = new Principal( |
|
| 48 | + $userManager, |
|
| 49 | + \OC::$server->getGroupManager() |
|
| 50 | + ); |
|
| 51 | + $groupPrincipalBackend = new GroupPrincipalBackend( |
|
| 52 | + \OC::$server->getGroupManager() |
|
| 53 | + ); |
|
| 54 | + $circlePrincipalBackend = new CirclePrincipalBackend(); |
|
| 55 | + // as soon as debug mode is enabled we allow listing of principals |
|
| 56 | + $disableListing = !$config->getSystemValue('debug', false); |
|
| 57 | 57 | |
| 58 | - // setup the first level of the dav tree |
|
| 59 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 60 | - $userPrincipals->disableListing = $disableListing; |
|
| 61 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 62 | - $groupPrincipals->disableListing = $disableListing; |
|
| 63 | - $circlePrincipals = new Collection($circlePrincipalBackend, 'principals/circles'); |
|
| 64 | - $circlePrincipals->disableListing = $disableListing; |
|
| 65 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 66 | - $systemPrincipals->disableListing = $disableListing; |
|
| 67 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 68 | - $filesCollection->disableListing = $disableListing; |
|
| 69 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 70 | - $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 71 | - $calendarRoot->disableListing = $disableListing; |
|
| 72 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 73 | - $publicCalendarRoot->disableListing = $disableListing; |
|
| 58 | + // setup the first level of the dav tree |
|
| 59 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
| 60 | + $userPrincipals->disableListing = $disableListing; |
|
| 61 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
| 62 | + $groupPrincipals->disableListing = $disableListing; |
|
| 63 | + $circlePrincipals = new Collection($circlePrincipalBackend, 'principals/circles'); |
|
| 64 | + $circlePrincipals->disableListing = $disableListing; |
|
| 65 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
| 66 | + $systemPrincipals->disableListing = $disableListing; |
|
| 67 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 68 | + $filesCollection->disableListing = $disableListing; |
|
| 69 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $random, $dispatcher); |
|
| 70 | + $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
| 71 | + $calendarRoot->disableListing = $disableListing; |
|
| 72 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
| 73 | + $publicCalendarRoot->disableListing = $disableListing; |
|
| 74 | 74 | |
| 75 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 76 | - \OC::$server->getSystemTagManager(), |
|
| 77 | - \OC::$server->getUserSession(), |
|
| 78 | - \OC::$server->getGroupManager() |
|
| 79 | - ); |
|
| 80 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 81 | - \OC::$server->getSystemTagManager(), |
|
| 82 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 83 | - \OC::$server->getUserSession(), |
|
| 84 | - \OC::$server->getGroupManager(), |
|
| 85 | - \OC::$server->getEventDispatcher() |
|
| 86 | - ); |
|
| 87 | - $commentsCollection = new Comments\RootCollection( |
|
| 88 | - \OC::$server->getCommentsManager(), |
|
| 89 | - \OC::$server->getUserManager(), |
|
| 90 | - \OC::$server->getUserSession(), |
|
| 91 | - \OC::$server->getEventDispatcher(), |
|
| 92 | - \OC::$server->getLogger() |
|
| 93 | - ); |
|
| 75 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
| 76 | + \OC::$server->getSystemTagManager(), |
|
| 77 | + \OC::$server->getUserSession(), |
|
| 78 | + \OC::$server->getGroupManager() |
|
| 79 | + ); |
|
| 80 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
| 81 | + \OC::$server->getSystemTagManager(), |
|
| 82 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 83 | + \OC::$server->getUserSession(), |
|
| 84 | + \OC::$server->getGroupManager(), |
|
| 85 | + \OC::$server->getEventDispatcher() |
|
| 86 | + ); |
|
| 87 | + $commentsCollection = new Comments\RootCollection( |
|
| 88 | + \OC::$server->getCommentsManager(), |
|
| 89 | + \OC::$server->getUserManager(), |
|
| 90 | + \OC::$server->getUserSession(), |
|
| 91 | + \OC::$server->getEventDispatcher(), |
|
| 92 | + \OC::$server->getLogger() |
|
| 93 | + ); |
|
| 94 | 94 | |
| 95 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 97 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
| 95 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 96 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
| 97 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
| 98 | 98 | |
| 99 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 100 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 101 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
| 99 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
| 100 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
| 101 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
| 102 | 102 | |
| 103 | - $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 104 | - $uploadCollection->disableListing = $disableListing; |
|
| 103 | + $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 104 | + $uploadCollection->disableListing = $disableListing; |
|
| 105 | 105 | |
| 106 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 107 | - $avatarCollection->disableListing = $disableListing; |
|
| 108 | - $children = [ |
|
| 109 | - new SimpleCollection('principals', [ |
|
| 110 | - $userPrincipals, |
|
| 111 | - $groupPrincipals, |
|
| 112 | - $circlePrincipals, |
|
| 113 | - $systemPrincipals]), |
|
| 114 | - $filesCollection, |
|
| 115 | - $calendarRoot, |
|
| 116 | - $publicCalendarRoot, |
|
| 117 | - new SimpleCollection('addressbooks', [ |
|
| 118 | - $usersAddressBookRoot, |
|
| 119 | - $systemAddressBookRoot]), |
|
| 120 | - $systemTagCollection, |
|
| 121 | - $systemTagRelationsCollection, |
|
| 122 | - $commentsCollection, |
|
| 123 | - $uploadCollection, |
|
| 124 | - $avatarCollection |
|
| 125 | - ]; |
|
| 106 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
| 107 | + $avatarCollection->disableListing = $disableListing; |
|
| 108 | + $children = [ |
|
| 109 | + new SimpleCollection('principals', [ |
|
| 110 | + $userPrincipals, |
|
| 111 | + $groupPrincipals, |
|
| 112 | + $circlePrincipals, |
|
| 113 | + $systemPrincipals]), |
|
| 114 | + $filesCollection, |
|
| 115 | + $calendarRoot, |
|
| 116 | + $publicCalendarRoot, |
|
| 117 | + new SimpleCollection('addressbooks', [ |
|
| 118 | + $usersAddressBookRoot, |
|
| 119 | + $systemAddressBookRoot]), |
|
| 120 | + $systemTagCollection, |
|
| 121 | + $systemTagRelationsCollection, |
|
| 122 | + $commentsCollection, |
|
| 123 | + $uploadCollection, |
|
| 124 | + $avatarCollection |
|
| 125 | + ]; |
|
| 126 | 126 | |
| 127 | - parent::__construct('root', $children); |
|
| 128 | - } |
|
| 127 | + parent::__construct('root', $children); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | 130 | } |
@@ -7,79 +7,79 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Broadcaster implements IBroadcaster { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * {@inheritdoc} |
|
| 12 | - */ |
|
| 13 | - public function init() { |
|
| 10 | + /** |
|
| 11 | + * {@inheritdoc} |
|
| 12 | + */ |
|
| 13 | + public function init() { |
|
| 14 | 14 | // $app = new Application(); |
| 15 | 15 | // $c = $app->getContainer(); |
| 16 | 16 | // |
| 17 | 17 | // $this->activityManager = $c->query('ActivityManager'); |
| 18 | - } |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * {@inheritdoc} |
|
| 22 | - */ |
|
| 23 | - public function createShareToUser(SharingFrame $frame, $userId) { |
|
| 24 | - return true; |
|
| 25 | - } |
|
| 20 | + /** |
|
| 21 | + * {@inheritdoc} |
|
| 22 | + */ |
|
| 23 | + public function createShareToUser(SharingFrame $frame, $userId) { |
|
| 24 | + return true; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * {@inheritdoc} |
|
| 30 | - */ |
|
| 31 | - public function createShareToCircle(SharingFrame $frame) { |
|
| 28 | + /** |
|
| 29 | + * {@inheritdoc} |
|
| 30 | + */ |
|
| 31 | + public function createShareToCircle(SharingFrame $frame) { |
|
| 32 | 32 | |
| 33 | - try { |
|
| 34 | - $data = $frame->getPayload(); |
|
| 33 | + try { |
|
| 34 | + $data = $frame->getPayload(); |
|
| 35 | 35 | |
| 36 | - $userPrincipalBackend = new \OCA\DAV\Connector\Sabre\Principal( |
|
| 37 | - \OC::$server->getUserManager(), |
|
| 38 | - \OC::$server->getGroupManager() |
|
| 39 | - ); |
|
| 36 | + $userPrincipalBackend = new \OCA\DAV\Connector\Sabre\Principal( |
|
| 37 | + \OC::$server->getUserManager(), |
|
| 38 | + \OC::$server->getGroupManager() |
|
| 39 | + ); |
|
| 40 | 40 | |
| 41 | - $caldavBackend = new \OCA\DAV\CalDAV\CalDavBackend(\OC::$server->getDatabaseConnection(), |
|
| 42 | - $userPrincipalBackend, \OC::$server->getUserManager(), \OC::$server->getSecureRandom(), \OC::$server->getEventDispatcher()); |
|
| 41 | + $caldavBackend = new \OCA\DAV\CalDAV\CalDavBackend(\OC::$server->getDatabaseConnection(), |
|
| 42 | + $userPrincipalBackend, \OC::$server->getUserManager(), \OC::$server->getSecureRandom(), \OC::$server->getEventDispatcher()); |
|
| 43 | 43 | |
| 44 | - $calendar = new \OCA\DAV\CalDAV\Calendar($caldavBackend, $data['calendar'], \OC::$server->getL10N('calendar')); |
|
| 45 | - $caldavBackend->updateShares($calendar, [$data['add']], []); |
|
| 44 | + $calendar = new \OCA\DAV\CalDAV\Calendar($caldavBackend, $data['calendar'], \OC::$server->getL10N('calendar')); |
|
| 45 | + $caldavBackend->updateShares($calendar, [$data['add']], []); |
|
| 46 | 46 | |
| 47 | - return true; |
|
| 48 | - } catch (\Exception $e) { |
|
| 49 | - return false; |
|
| 50 | - } |
|
| 51 | - } |
|
| 47 | + return true; |
|
| 48 | + } catch (\Exception $e) { |
|
| 49 | + return false; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * {@inheritdoc} |
|
| 56 | - */ |
|
| 57 | - public function deleteShareToCircle(SharingFrame $frame) { |
|
| 58 | - return true; |
|
| 59 | - } |
|
| 54 | + /** |
|
| 55 | + * {@inheritdoc} |
|
| 56 | + */ |
|
| 57 | + public function deleteShareToCircle(SharingFrame $frame) { |
|
| 58 | + return true; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * {@inheritdoc} |
|
| 64 | - */ |
|
| 65 | - public function editShareToCircle(SharingFrame $frame) { |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 62 | + /** |
|
| 63 | + * {@inheritdoc} |
|
| 64 | + */ |
|
| 65 | + public function editShareToCircle(SharingFrame $frame) { |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritdoc} |
|
| 72 | - */ |
|
| 73 | - public function deleteShareToUser(SharingFrame $frame, $userId) { |
|
| 74 | - return true; |
|
| 75 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritdoc} |
|
| 72 | + */ |
|
| 73 | + public function deleteShareToUser(SharingFrame $frame, $userId) { |
|
| 74 | + return true; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * {@inheritdoc} |
|
| 80 | - */ |
|
| 81 | - public function editShareToUser(SharingFrame $frame, $userId) { |
|
| 82 | - return true; |
|
| 83 | - } |
|
| 78 | + /** |
|
| 79 | + * {@inheritdoc} |
|
| 80 | + */ |
|
| 81 | + public function editShareToUser(SharingFrame $frame, $userId) { |
|
| 82 | + return true; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | \ No newline at end of file |
@@ -40,204 +40,204 @@ |
||
| 40 | 40 | |
| 41 | 41 | class Principal implements BackendInterface { |
| 42 | 42 | |
| 43 | - /** @var IUserManager */ |
|
| 44 | - private $userManager; |
|
| 45 | - |
|
| 46 | - /** @var IGroupManager */ |
|
| 47 | - private $groupManager; |
|
| 48 | - |
|
| 49 | - /** @var string */ |
|
| 50 | - private $principalPrefix; |
|
| 51 | - |
|
| 52 | - /** @var bool */ |
|
| 53 | - private $hasGroups; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param IUserManager $userManager |
|
| 57 | - * @param IGroupManager $groupManager |
|
| 58 | - * @param string $principalPrefix |
|
| 59 | - */ |
|
| 60 | - public function __construct(IUserManager $userManager, |
|
| 61 | - IGroupManager $groupManager, |
|
| 62 | - $principalPrefix = 'principals/users/') { |
|
| 63 | - $this->userManager = $userManager; |
|
| 64 | - $this->groupManager = $groupManager; |
|
| 65 | - $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 66 | - $this->hasGroups = ($principalPrefix === 'principals/users/'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Returns a list of principals based on a prefix. |
|
| 71 | - * |
|
| 72 | - * This prefix will often contain something like 'principals'. You are only |
|
| 73 | - * expected to return principals that are in this base path. |
|
| 74 | - * |
|
| 75 | - * You are expected to return at least a 'uri' for every user, you can |
|
| 76 | - * return any additional properties if you wish so. Common properties are: |
|
| 77 | - * {DAV:}displayname |
|
| 78 | - * |
|
| 79 | - * @param string $prefixPath |
|
| 80 | - * @return string[] |
|
| 81 | - */ |
|
| 82 | - public function getPrincipalsByPrefix($prefixPath) { |
|
| 83 | - $principals = []; |
|
| 84 | - |
|
| 85 | - if ($prefixPath === $this->principalPrefix) { |
|
| 86 | - foreach($this->userManager->search('') as $user) { |
|
| 87 | - $principals[] = $this->userToPrincipal($user); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $principals; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Returns a specific principal, specified by it's path. |
|
| 96 | - * The returned structure should be the exact same as from |
|
| 97 | - * getPrincipalsByPrefix. |
|
| 98 | - * |
|
| 99 | - * @param string $path |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function getPrincipalByPath($path) { |
|
| 103 | - list($prefix, $name) = URLUtil::splitPath($path); |
|
| 104 | - |
|
| 105 | - if ($prefix === $this->principalPrefix) { |
|
| 106 | - $user = $this->userManager->get($name); |
|
| 107 | - |
|
| 108 | - if (!is_null($user)) { |
|
| 109 | - return $this->userToPrincipal($user); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return null; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Returns the list of members for a group-principal |
|
| 117 | - * |
|
| 118 | - * @param string $principal |
|
| 119 | - * @return string[] |
|
| 120 | - * @throws Exception |
|
| 121 | - */ |
|
| 122 | - public function getGroupMemberSet($principal) { |
|
| 123 | - // TODO: for now the group principal has only one member, the user itself |
|
| 124 | - $principal = $this->getPrincipalByPath($principal); |
|
| 125 | - if (!$principal) { |
|
| 126 | - throw new Exception('Principal not found'); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return [$principal['uri']]; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns the list of groups a principal is a member of |
|
| 134 | - * |
|
| 135 | - * @param string $principal |
|
| 136 | - * @param bool $needGroups |
|
| 137 | - * @return array |
|
| 138 | - * @throws Exception |
|
| 139 | - */ |
|
| 140 | - public function getGroupMembership($principal, $needGroups = false) { |
|
| 141 | - list($prefix, $name) = URLUtil::splitPath($principal); |
|
| 142 | - |
|
| 143 | - if ($prefix === $this->principalPrefix) { |
|
| 144 | - $user = $this->userManager->get($name); |
|
| 145 | - if (!$user) { |
|
| 146 | - throw new Exception('Principal not found'); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($this->hasGroups || $needGroups) { |
|
| 150 | - |
|
| 151 | - $groups = $this->groupManager->getUserGroups($user); |
|
| 152 | - $groups = array_map(function($group) { |
|
| 153 | - /** @var IGroup $group */ |
|
| 154 | - return 'principals/groups/' . urlencode($group->getGID()); |
|
| 155 | - }, $groups); |
|
| 156 | - |
|
| 157 | - // We also add circles to the group list. |
|
| 158 | - // TODO: will generate conflict if the circle has the same name than a group |
|
| 159 | - $circles = \OCA\Circles\Api\v1\Circles::joinedCircles(); |
|
| 160 | - foreach ($circles as $circle) { |
|
| 161 | - $groups['_circle_' . $circle->getId()] = 'principals/circles/' . $circle->getId(); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return $groups; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return []; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Updates the list of group members for a group principal. |
|
| 172 | - * |
|
| 173 | - * The principals should be passed as a list of uri's. |
|
| 174 | - * |
|
| 175 | - * @param string $principal |
|
| 176 | - * @param string[] $members |
|
| 177 | - * @throws Exception |
|
| 178 | - */ |
|
| 179 | - public function setGroupMemberSet($principal, array $members) { |
|
| 180 | - throw new Exception('Setting members of the group is not supported yet'); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @param string $path |
|
| 185 | - * @param PropPatch $propPatch |
|
| 186 | - * @return int |
|
| 187 | - */ |
|
| 188 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
| 189 | - return 0; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * @param string $prefixPath |
|
| 194 | - * @param array $searchProperties |
|
| 195 | - * @param string $test |
|
| 196 | - * @return array |
|
| 197 | - */ |
|
| 198 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 199 | - return []; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @param string $uri |
|
| 204 | - * @param string $principalPrefix |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 207 | - function findByUri($uri, $principalPrefix) { |
|
| 208 | - if (substr($uri, 0, 7) === 'mailto:') { |
|
| 209 | - $email = substr($uri, 7); |
|
| 210 | - $users = $this->userManager->getByEmail($email); |
|
| 211 | - if (count($users) === 1) { |
|
| 212 | - return $this->principalPrefix . '/' . $users[0]->getUID(); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param IUser $user |
|
| 221 | - * @return array |
|
| 222 | - */ |
|
| 223 | - protected function userToPrincipal($user) { |
|
| 224 | - $userId = $user->getUID(); |
|
| 225 | - $displayName = $user->getDisplayName(); |
|
| 226 | - $principal = [ |
|
| 227 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 228 | - '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 229 | - ]; |
|
| 230 | - |
|
| 231 | - $email = $user->getEMailAddress(); |
|
| 232 | - if (!empty($email)) { |
|
| 233 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return $principal; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - public function getPrincipalPrefix() { |
|
| 240 | - return $this->principalPrefix; |
|
| 241 | - } |
|
| 43 | + /** @var IUserManager */ |
|
| 44 | + private $userManager; |
|
| 45 | + |
|
| 46 | + /** @var IGroupManager */ |
|
| 47 | + private $groupManager; |
|
| 48 | + |
|
| 49 | + /** @var string */ |
|
| 50 | + private $principalPrefix; |
|
| 51 | + |
|
| 52 | + /** @var bool */ |
|
| 53 | + private $hasGroups; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param IUserManager $userManager |
|
| 57 | + * @param IGroupManager $groupManager |
|
| 58 | + * @param string $principalPrefix |
|
| 59 | + */ |
|
| 60 | + public function __construct(IUserManager $userManager, |
|
| 61 | + IGroupManager $groupManager, |
|
| 62 | + $principalPrefix = 'principals/users/') { |
|
| 63 | + $this->userManager = $userManager; |
|
| 64 | + $this->groupManager = $groupManager; |
|
| 65 | + $this->principalPrefix = trim($principalPrefix, '/'); |
|
| 66 | + $this->hasGroups = ($principalPrefix === 'principals/users/'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Returns a list of principals based on a prefix. |
|
| 71 | + * |
|
| 72 | + * This prefix will often contain something like 'principals'. You are only |
|
| 73 | + * expected to return principals that are in this base path. |
|
| 74 | + * |
|
| 75 | + * You are expected to return at least a 'uri' for every user, you can |
|
| 76 | + * return any additional properties if you wish so. Common properties are: |
|
| 77 | + * {DAV:}displayname |
|
| 78 | + * |
|
| 79 | + * @param string $prefixPath |
|
| 80 | + * @return string[] |
|
| 81 | + */ |
|
| 82 | + public function getPrincipalsByPrefix($prefixPath) { |
|
| 83 | + $principals = []; |
|
| 84 | + |
|
| 85 | + if ($prefixPath === $this->principalPrefix) { |
|
| 86 | + foreach($this->userManager->search('') as $user) { |
|
| 87 | + $principals[] = $this->userToPrincipal($user); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $principals; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Returns a specific principal, specified by it's path. |
|
| 96 | + * The returned structure should be the exact same as from |
|
| 97 | + * getPrincipalsByPrefix. |
|
| 98 | + * |
|
| 99 | + * @param string $path |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function getPrincipalByPath($path) { |
|
| 103 | + list($prefix, $name) = URLUtil::splitPath($path); |
|
| 104 | + |
|
| 105 | + if ($prefix === $this->principalPrefix) { |
|
| 106 | + $user = $this->userManager->get($name); |
|
| 107 | + |
|
| 108 | + if (!is_null($user)) { |
|
| 109 | + return $this->userToPrincipal($user); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return null; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Returns the list of members for a group-principal |
|
| 117 | + * |
|
| 118 | + * @param string $principal |
|
| 119 | + * @return string[] |
|
| 120 | + * @throws Exception |
|
| 121 | + */ |
|
| 122 | + public function getGroupMemberSet($principal) { |
|
| 123 | + // TODO: for now the group principal has only one member, the user itself |
|
| 124 | + $principal = $this->getPrincipalByPath($principal); |
|
| 125 | + if (!$principal) { |
|
| 126 | + throw new Exception('Principal not found'); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return [$principal['uri']]; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns the list of groups a principal is a member of |
|
| 134 | + * |
|
| 135 | + * @param string $principal |
|
| 136 | + * @param bool $needGroups |
|
| 137 | + * @return array |
|
| 138 | + * @throws Exception |
|
| 139 | + */ |
|
| 140 | + public function getGroupMembership($principal, $needGroups = false) { |
|
| 141 | + list($prefix, $name) = URLUtil::splitPath($principal); |
|
| 142 | + |
|
| 143 | + if ($prefix === $this->principalPrefix) { |
|
| 144 | + $user = $this->userManager->get($name); |
|
| 145 | + if (!$user) { |
|
| 146 | + throw new Exception('Principal not found'); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($this->hasGroups || $needGroups) { |
|
| 150 | + |
|
| 151 | + $groups = $this->groupManager->getUserGroups($user); |
|
| 152 | + $groups = array_map(function($group) { |
|
| 153 | + /** @var IGroup $group */ |
|
| 154 | + return 'principals/groups/' . urlencode($group->getGID()); |
|
| 155 | + }, $groups); |
|
| 156 | + |
|
| 157 | + // We also add circles to the group list. |
|
| 158 | + // TODO: will generate conflict if the circle has the same name than a group |
|
| 159 | + $circles = \OCA\Circles\Api\v1\Circles::joinedCircles(); |
|
| 160 | + foreach ($circles as $circle) { |
|
| 161 | + $groups['_circle_' . $circle->getId()] = 'principals/circles/' . $circle->getId(); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return $groups; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return []; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Updates the list of group members for a group principal. |
|
| 172 | + * |
|
| 173 | + * The principals should be passed as a list of uri's. |
|
| 174 | + * |
|
| 175 | + * @param string $principal |
|
| 176 | + * @param string[] $members |
|
| 177 | + * @throws Exception |
|
| 178 | + */ |
|
| 179 | + public function setGroupMemberSet($principal, array $members) { |
|
| 180 | + throw new Exception('Setting members of the group is not supported yet'); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @param string $path |
|
| 185 | + * @param PropPatch $propPatch |
|
| 186 | + * @return int |
|
| 187 | + */ |
|
| 188 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
| 189 | + return 0; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * @param string $prefixPath |
|
| 194 | + * @param array $searchProperties |
|
| 195 | + * @param string $test |
|
| 196 | + * @return array |
|
| 197 | + */ |
|
| 198 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 199 | + return []; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @param string $uri |
|
| 204 | + * @param string $principalPrefix |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | + function findByUri($uri, $principalPrefix) { |
|
| 208 | + if (substr($uri, 0, 7) === 'mailto:') { |
|
| 209 | + $email = substr($uri, 7); |
|
| 210 | + $users = $this->userManager->getByEmail($email); |
|
| 211 | + if (count($users) === 1) { |
|
| 212 | + return $this->principalPrefix . '/' . $users[0]->getUID(); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param IUser $user |
|
| 221 | + * @return array |
|
| 222 | + */ |
|
| 223 | + protected function userToPrincipal($user) { |
|
| 224 | + $userId = $user->getUID(); |
|
| 225 | + $displayName = $user->getDisplayName(); |
|
| 226 | + $principal = [ |
|
| 227 | + 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 228 | + '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
|
| 229 | + ]; |
|
| 230 | + |
|
| 231 | + $email = $user->getEMailAddress(); |
|
| 232 | + if (!empty($email)) { |
|
| 233 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return $principal; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + public function getPrincipalPrefix() { |
|
| 240 | + return $this->principalPrefix; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | 243 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $principals = []; |
| 84 | 84 | |
| 85 | 85 | if ($prefixPath === $this->principalPrefix) { |
| 86 | - foreach($this->userManager->search('') as $user) { |
|
| 86 | + foreach ($this->userManager->search('') as $user) { |
|
| 87 | 87 | $principals[] = $this->userToPrincipal($user); |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | $groups = $this->groupManager->getUserGroups($user); |
| 152 | 152 | $groups = array_map(function($group) { |
| 153 | 153 | /** @var IGroup $group */ |
| 154 | - return 'principals/groups/' . urlencode($group->getGID()); |
|
| 154 | + return 'principals/groups/'.urlencode($group->getGID()); |
|
| 155 | 155 | }, $groups); |
| 156 | 156 | |
| 157 | 157 | // We also add circles to the group list. |
| 158 | 158 | // TODO: will generate conflict if the circle has the same name than a group |
| 159 | 159 | $circles = \OCA\Circles\Api\v1\Circles::joinedCircles(); |
| 160 | 160 | foreach ($circles as $circle) { |
| 161 | - $groups['_circle_' . $circle->getId()] = 'principals/circles/' . $circle->getId(); |
|
| 161 | + $groups['_circle_'.$circle->getId()] = 'principals/circles/'.$circle->getId(); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | return $groups; |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $email = substr($uri, 7); |
| 210 | 210 | $users = $this->userManager->getByEmail($email); |
| 211 | 211 | if (count($users) === 1) { |
| 212 | - return $this->principalPrefix . '/' . $users[0]->getUID(); |
|
| 212 | + return $this->principalPrefix.'/'.$users[0]->getUID(); |
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $userId = $user->getUID(); |
| 225 | 225 | $displayName = $user->getDisplayName(); |
| 226 | 226 | $principal = [ |
| 227 | - 'uri' => $this->principalPrefix . '/' . $userId, |
|
| 227 | + 'uri' => $this->principalPrefix.'/'.$userId, |
|
| 228 | 228 | '{DAV:}displayname' => is_null($displayName) ? $userId : $displayName, |
| 229 | 229 | ]; |
| 230 | 230 | |