@@ -59,905 +59,905 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | class ShareAPIController extends OCSController { |
| 61 | 61 | |
| 62 | - /** @var IManager */ |
|
| 63 | - private $shareManager; |
|
| 64 | - /** @var IGroupManager */ |
|
| 65 | - private $groupManager; |
|
| 66 | - /** @var IUserManager */ |
|
| 67 | - private $userManager; |
|
| 68 | - /** @var IRequest */ |
|
| 69 | - protected $request; |
|
| 70 | - /** @var IRootFolder */ |
|
| 71 | - private $rootFolder; |
|
| 72 | - /** @var IURLGenerator */ |
|
| 73 | - private $urlGenerator; |
|
| 74 | - /** @var string */ |
|
| 75 | - private $currentUser; |
|
| 76 | - /** @var IL10N */ |
|
| 77 | - private $l; |
|
| 78 | - /** @var \OCP\Files\Node */ |
|
| 79 | - private $lockedNode; |
|
| 80 | - /** @var IConfig */ |
|
| 81 | - private $config; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Share20OCS constructor. |
|
| 85 | - * |
|
| 86 | - * @param string $appName |
|
| 87 | - * @param IRequest $request |
|
| 88 | - * @param IManager $shareManager |
|
| 89 | - * @param IGroupManager $groupManager |
|
| 90 | - * @param IUserManager $userManager |
|
| 91 | - * @param IRootFolder $rootFolder |
|
| 92 | - * @param IURLGenerator $urlGenerator |
|
| 93 | - * @param string $userId |
|
| 94 | - * @param IL10N $l10n |
|
| 95 | - * @param IConfig $config |
|
| 96 | - */ |
|
| 97 | - public function __construct( |
|
| 98 | - $appName, |
|
| 99 | - IRequest $request, |
|
| 100 | - IManager $shareManager, |
|
| 101 | - IGroupManager $groupManager, |
|
| 102 | - IUserManager $userManager, |
|
| 103 | - IRootFolder $rootFolder, |
|
| 104 | - IURLGenerator $urlGenerator, |
|
| 105 | - $userId, |
|
| 106 | - IL10N $l10n, |
|
| 107 | - IConfig $config |
|
| 108 | - ) { |
|
| 109 | - parent::__construct($appName, $request); |
|
| 110 | - |
|
| 111 | - $this->shareManager = $shareManager; |
|
| 112 | - $this->userManager = $userManager; |
|
| 113 | - $this->groupManager = $groupManager; |
|
| 114 | - $this->request = $request; |
|
| 115 | - $this->rootFolder = $rootFolder; |
|
| 116 | - $this->urlGenerator = $urlGenerator; |
|
| 117 | - $this->currentUser = $userId; |
|
| 118 | - $this->l = $l10n; |
|
| 119 | - $this->config = $config; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Convert an IShare to an array for OCS output |
|
| 124 | - * |
|
| 125 | - * @param \OCP\Share\IShare $share |
|
| 126 | - * @param Node|null $recipientNode |
|
| 127 | - * @return array |
|
| 128 | - * @throws NotFoundException In case the node can't be resolved. |
|
| 129 | - */ |
|
| 130 | - protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 131 | - $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 132 | - $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 133 | - |
|
| 134 | - $result = [ |
|
| 135 | - 'id' => $share->getId(), |
|
| 136 | - 'share_type' => $share->getShareType(), |
|
| 137 | - 'uid_owner' => $share->getSharedBy(), |
|
| 138 | - 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 139 | - 'permissions' => $share->getPermissions(), |
|
| 140 | - 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 141 | - 'parent' => null, |
|
| 142 | - 'expiration' => null, |
|
| 143 | - 'token' => null, |
|
| 144 | - 'uid_file_owner' => $share->getShareOwner(), |
|
| 145 | - 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 146 | - ]; |
|
| 147 | - |
|
| 148 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 149 | - if ($recipientNode) { |
|
| 150 | - $node = $recipientNode; |
|
| 151 | - } else { |
|
| 152 | - $nodes = $userFolder->getById($share->getNodeId()); |
|
| 153 | - |
|
| 154 | - if (empty($nodes)) { |
|
| 155 | - // fallback to guessing the path |
|
| 156 | - $node = $userFolder->get($share->getTarget()); |
|
| 157 | - if ($node === null) { |
|
| 158 | - throw new NotFoundException(); |
|
| 159 | - } |
|
| 160 | - } else { |
|
| 161 | - $node = $nodes[0]; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 166 | - if ($node instanceOf \OCP\Files\Folder) { |
|
| 167 | - $result['item_type'] = 'folder'; |
|
| 168 | - } else { |
|
| 169 | - $result['item_type'] = 'file'; |
|
| 170 | - } |
|
| 171 | - $result['mimetype'] = $node->getMimetype(); |
|
| 172 | - $result['storage_id'] = $node->getStorage()->getId(); |
|
| 173 | - $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 174 | - $result['item_source'] = $node->getId(); |
|
| 175 | - $result['file_source'] = $node->getId(); |
|
| 176 | - $result['file_parent'] = $node->getParent()->getId(); |
|
| 177 | - $result['file_target'] = $share->getTarget(); |
|
| 178 | - |
|
| 179 | - $expiration = $share->getExpirationDate(); |
|
| 180 | - if ($expiration !== null) { |
|
| 181 | - $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 185 | - $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 186 | - $result['share_with'] = $share->getSharedWith(); |
|
| 187 | - $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 188 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 189 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
| 190 | - $result['share_with'] = $share->getSharedWith(); |
|
| 191 | - $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 192 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 193 | - |
|
| 194 | - $result['share_with'] = $share->getPassword(); |
|
| 195 | - $result['share_with_displayname'] = $share->getPassword(); |
|
| 196 | - |
|
| 197 | - $result['token'] = $share->getToken(); |
|
| 198 | - $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 199 | - |
|
| 200 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 201 | - $result['share_with'] = $share->getSharedWith(); |
|
| 202 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 203 | - $result['token'] = $share->getToken(); |
|
| 204 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 205 | - $result['share_with'] = $share->getSharedWith(); |
|
| 206 | - $result['password'] = $share->getPassword(); |
|
| 207 | - $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 208 | - $result['token'] = $share->getToken(); |
|
| 209 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 210 | - // getSharedWith() returns either "name (type, owner)" or |
|
| 211 | - // "name (type, owner) [id]", depending on the Circles app version. |
|
| 212 | - $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); |
|
| 213 | - |
|
| 214 | - $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith())); |
|
| 215 | - $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength); |
|
| 216 | - |
|
| 217 | - $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0); |
|
| 218 | - $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' ')); |
|
| 219 | - $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 224 | - |
|
| 225 | - return $result; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Check if one of the users address books knows the exact property, if |
|
| 230 | - * yes we return the full name. |
|
| 231 | - * |
|
| 232 | - * @param string $query |
|
| 233 | - * @param string $property |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - private function getDisplayNameFromAddressBook($query, $property) { |
|
| 237 | - // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 238 | - $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 239 | - foreach ($result as $r) { |
|
| 240 | - foreach($r[$property] as $value) { |
|
| 241 | - if ($value === $query) { |
|
| 242 | - return $r['FN']; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return $query; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Get a specific share by id |
|
| 252 | - * |
|
| 253 | - * @NoAdminRequired |
|
| 254 | - * |
|
| 255 | - * @param string $id |
|
| 256 | - * @return DataResponse |
|
| 257 | - * @throws OCSNotFoundException |
|
| 258 | - */ |
|
| 259 | - public function getShare($id) { |
|
| 260 | - try { |
|
| 261 | - $share = $this->getShareById($id); |
|
| 262 | - } catch (ShareNotFound $e) { |
|
| 263 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - if ($this->canAccessShare($share)) { |
|
| 267 | - try { |
|
| 268 | - $share = $this->formatShare($share); |
|
| 269 | - return new DataResponse([$share]); |
|
| 270 | - } catch (NotFoundException $e) { |
|
| 271 | - //Fall trough |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Delete a share |
|
| 280 | - * |
|
| 281 | - * @NoAdminRequired |
|
| 282 | - * |
|
| 283 | - * @param string $id |
|
| 284 | - * @return DataResponse |
|
| 285 | - * @throws OCSNotFoundException |
|
| 286 | - */ |
|
| 287 | - public function deleteShare($id) { |
|
| 288 | - try { |
|
| 289 | - $share = $this->getShareById($id); |
|
| 290 | - } catch (ShareNotFound $e) { |
|
| 291 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - try { |
|
| 295 | - $this->lock($share->getNode()); |
|
| 296 | - } catch (LockedException $e) { |
|
| 297 | - throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - if (!$this->canAccessShare($share)) { |
|
| 301 | - throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 305 | - $share->getShareOwner() !== $this->currentUser && |
|
| 306 | - $share->getSharedBy() !== $this->currentUser) { |
|
| 307 | - $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 308 | - } else { |
|
| 309 | - $this->shareManager->deleteShare($share); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return new DataResponse(); |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * @NoAdminRequired |
|
| 317 | - * |
|
| 318 | - * @param string $path |
|
| 319 | - * @param int $permissions |
|
| 320 | - * @param int $shareType |
|
| 321 | - * @param string $shareWith |
|
| 322 | - * @param string $publicUpload |
|
| 323 | - * @param string $password |
|
| 324 | - * @param string $expireDate |
|
| 325 | - * |
|
| 326 | - * @return DataResponse |
|
| 327 | - * @throws OCSNotFoundException |
|
| 328 | - * @throws OCSForbiddenException |
|
| 329 | - * @throws OCSBadRequestException |
|
| 330 | - * @throws OCSException |
|
| 331 | - * |
|
| 332 | - * @suppress PhanUndeclaredClassMethod |
|
| 333 | - */ |
|
| 334 | - public function createShare( |
|
| 335 | - $path = null, |
|
| 336 | - $permissions = null, |
|
| 337 | - $shareType = -1, |
|
| 338 | - $shareWith = null, |
|
| 339 | - $publicUpload = 'false', |
|
| 340 | - $password = '', |
|
| 341 | - $expireDate = '' |
|
| 342 | - ) { |
|
| 343 | - $share = $this->shareManager->newShare(); |
|
| 344 | - |
|
| 345 | - if ($permissions === null) { |
|
| 346 | - $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - // Verify path |
|
| 350 | - if ($path === null) { |
|
| 351 | - throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 355 | - try { |
|
| 356 | - $path = $userFolder->get($path); |
|
| 357 | - } catch (NotFoundException $e) { |
|
| 358 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $share->setNode($path); |
|
| 362 | - |
|
| 363 | - try { |
|
| 364 | - $this->lock($share->getNode()); |
|
| 365 | - } catch (LockedException $e) { |
|
| 366 | - throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
| 370 | - throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // Shares always require read permissions |
|
| 374 | - $permissions |= Constants::PERMISSION_READ; |
|
| 375 | - |
|
| 376 | - if ($path instanceof \OCP\Files\File) { |
|
| 377 | - // Single file shares should never have delete or create permissions |
|
| 378 | - $permissions &= ~Constants::PERMISSION_DELETE; |
|
| 379 | - $permissions &= ~Constants::PERMISSION_CREATE; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /* |
|
| 62 | + /** @var IManager */ |
|
| 63 | + private $shareManager; |
|
| 64 | + /** @var IGroupManager */ |
|
| 65 | + private $groupManager; |
|
| 66 | + /** @var IUserManager */ |
|
| 67 | + private $userManager; |
|
| 68 | + /** @var IRequest */ |
|
| 69 | + protected $request; |
|
| 70 | + /** @var IRootFolder */ |
|
| 71 | + private $rootFolder; |
|
| 72 | + /** @var IURLGenerator */ |
|
| 73 | + private $urlGenerator; |
|
| 74 | + /** @var string */ |
|
| 75 | + private $currentUser; |
|
| 76 | + /** @var IL10N */ |
|
| 77 | + private $l; |
|
| 78 | + /** @var \OCP\Files\Node */ |
|
| 79 | + private $lockedNode; |
|
| 80 | + /** @var IConfig */ |
|
| 81 | + private $config; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Share20OCS constructor. |
|
| 85 | + * |
|
| 86 | + * @param string $appName |
|
| 87 | + * @param IRequest $request |
|
| 88 | + * @param IManager $shareManager |
|
| 89 | + * @param IGroupManager $groupManager |
|
| 90 | + * @param IUserManager $userManager |
|
| 91 | + * @param IRootFolder $rootFolder |
|
| 92 | + * @param IURLGenerator $urlGenerator |
|
| 93 | + * @param string $userId |
|
| 94 | + * @param IL10N $l10n |
|
| 95 | + * @param IConfig $config |
|
| 96 | + */ |
|
| 97 | + public function __construct( |
|
| 98 | + $appName, |
|
| 99 | + IRequest $request, |
|
| 100 | + IManager $shareManager, |
|
| 101 | + IGroupManager $groupManager, |
|
| 102 | + IUserManager $userManager, |
|
| 103 | + IRootFolder $rootFolder, |
|
| 104 | + IURLGenerator $urlGenerator, |
|
| 105 | + $userId, |
|
| 106 | + IL10N $l10n, |
|
| 107 | + IConfig $config |
|
| 108 | + ) { |
|
| 109 | + parent::__construct($appName, $request); |
|
| 110 | + |
|
| 111 | + $this->shareManager = $shareManager; |
|
| 112 | + $this->userManager = $userManager; |
|
| 113 | + $this->groupManager = $groupManager; |
|
| 114 | + $this->request = $request; |
|
| 115 | + $this->rootFolder = $rootFolder; |
|
| 116 | + $this->urlGenerator = $urlGenerator; |
|
| 117 | + $this->currentUser = $userId; |
|
| 118 | + $this->l = $l10n; |
|
| 119 | + $this->config = $config; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Convert an IShare to an array for OCS output |
|
| 124 | + * |
|
| 125 | + * @param \OCP\Share\IShare $share |
|
| 126 | + * @param Node|null $recipientNode |
|
| 127 | + * @return array |
|
| 128 | + * @throws NotFoundException In case the node can't be resolved. |
|
| 129 | + */ |
|
| 130 | + protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null) { |
|
| 131 | + $sharedBy = $this->userManager->get($share->getSharedBy()); |
|
| 132 | + $shareOwner = $this->userManager->get($share->getShareOwner()); |
|
| 133 | + |
|
| 134 | + $result = [ |
|
| 135 | + 'id' => $share->getId(), |
|
| 136 | + 'share_type' => $share->getShareType(), |
|
| 137 | + 'uid_owner' => $share->getSharedBy(), |
|
| 138 | + 'displayname_owner' => $sharedBy !== null ? $sharedBy->getDisplayName() : $share->getSharedBy(), |
|
| 139 | + 'permissions' => $share->getPermissions(), |
|
| 140 | + 'stime' => $share->getShareTime()->getTimestamp(), |
|
| 141 | + 'parent' => null, |
|
| 142 | + 'expiration' => null, |
|
| 143 | + 'token' => null, |
|
| 144 | + 'uid_file_owner' => $share->getShareOwner(), |
|
| 145 | + 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), |
|
| 146 | + ]; |
|
| 147 | + |
|
| 148 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 149 | + if ($recipientNode) { |
|
| 150 | + $node = $recipientNode; |
|
| 151 | + } else { |
|
| 152 | + $nodes = $userFolder->getById($share->getNodeId()); |
|
| 153 | + |
|
| 154 | + if (empty($nodes)) { |
|
| 155 | + // fallback to guessing the path |
|
| 156 | + $node = $userFolder->get($share->getTarget()); |
|
| 157 | + if ($node === null) { |
|
| 158 | + throw new NotFoundException(); |
|
| 159 | + } |
|
| 160 | + } else { |
|
| 161 | + $node = $nodes[0]; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $result['path'] = $userFolder->getRelativePath($node->getPath()); |
|
| 166 | + if ($node instanceOf \OCP\Files\Folder) { |
|
| 167 | + $result['item_type'] = 'folder'; |
|
| 168 | + } else { |
|
| 169 | + $result['item_type'] = 'file'; |
|
| 170 | + } |
|
| 171 | + $result['mimetype'] = $node->getMimetype(); |
|
| 172 | + $result['storage_id'] = $node->getStorage()->getId(); |
|
| 173 | + $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId(); |
|
| 174 | + $result['item_source'] = $node->getId(); |
|
| 175 | + $result['file_source'] = $node->getId(); |
|
| 176 | + $result['file_parent'] = $node->getParent()->getId(); |
|
| 177 | + $result['file_target'] = $share->getTarget(); |
|
| 178 | + |
|
| 179 | + $expiration = $share->getExpirationDate(); |
|
| 180 | + if ($expiration !== null) { |
|
| 181 | + $result['expiration'] = $expiration->format('Y-m-d 00:00:00'); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
| 185 | + $sharedWith = $this->userManager->get($share->getSharedWith()); |
|
| 186 | + $result['share_with'] = $share->getSharedWith(); |
|
| 187 | + $result['share_with_displayname'] = $sharedWith !== null ? $sharedWith->getDisplayName() : $share->getSharedWith(); |
|
| 188 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 189 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
| 190 | + $result['share_with'] = $share->getSharedWith(); |
|
| 191 | + $result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith(); |
|
| 192 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 193 | + |
|
| 194 | + $result['share_with'] = $share->getPassword(); |
|
| 195 | + $result['share_with_displayname'] = $share->getPassword(); |
|
| 196 | + |
|
| 197 | + $result['token'] = $share->getToken(); |
|
| 198 | + $result['url'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); |
|
| 199 | + |
|
| 200 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 201 | + $result['share_with'] = $share->getSharedWith(); |
|
| 202 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'CLOUD'); |
|
| 203 | + $result['token'] = $share->getToken(); |
|
| 204 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 205 | + $result['share_with'] = $share->getSharedWith(); |
|
| 206 | + $result['password'] = $share->getPassword(); |
|
| 207 | + $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL'); |
|
| 208 | + $result['token'] = $share->getToken(); |
|
| 209 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 210 | + // getSharedWith() returns either "name (type, owner)" or |
|
| 211 | + // "name (type, owner) [id]", depending on the Circles app version. |
|
| 212 | + $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); |
|
| 213 | + |
|
| 214 | + $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith())); |
|
| 215 | + $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength); |
|
| 216 | + |
|
| 217 | + $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0); |
|
| 218 | + $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' ')); |
|
| 219 | + $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + $result['mail_send'] = $share->getMailSend() ? 1 : 0; |
|
| 224 | + |
|
| 225 | + return $result; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Check if one of the users address books knows the exact property, if |
|
| 230 | + * yes we return the full name. |
|
| 231 | + * |
|
| 232 | + * @param string $query |
|
| 233 | + * @param string $property |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + private function getDisplayNameFromAddressBook($query, $property) { |
|
| 237 | + // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
|
| 238 | + $result = \OC::$server->getContactsManager()->search($query, [$property]); |
|
| 239 | + foreach ($result as $r) { |
|
| 240 | + foreach($r[$property] as $value) { |
|
| 241 | + if ($value === $query) { |
|
| 242 | + return $r['FN']; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return $query; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Get a specific share by id |
|
| 252 | + * |
|
| 253 | + * @NoAdminRequired |
|
| 254 | + * |
|
| 255 | + * @param string $id |
|
| 256 | + * @return DataResponse |
|
| 257 | + * @throws OCSNotFoundException |
|
| 258 | + */ |
|
| 259 | + public function getShare($id) { |
|
| 260 | + try { |
|
| 261 | + $share = $this->getShareById($id); |
|
| 262 | + } catch (ShareNotFound $e) { |
|
| 263 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + if ($this->canAccessShare($share)) { |
|
| 267 | + try { |
|
| 268 | + $share = $this->formatShare($share); |
|
| 269 | + return new DataResponse([$share]); |
|
| 270 | + } catch (NotFoundException $e) { |
|
| 271 | + //Fall trough |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Delete a share |
|
| 280 | + * |
|
| 281 | + * @NoAdminRequired |
|
| 282 | + * |
|
| 283 | + * @param string $id |
|
| 284 | + * @return DataResponse |
|
| 285 | + * @throws OCSNotFoundException |
|
| 286 | + */ |
|
| 287 | + public function deleteShare($id) { |
|
| 288 | + try { |
|
| 289 | + $share = $this->getShareById($id); |
|
| 290 | + } catch (ShareNotFound $e) { |
|
| 291 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + try { |
|
| 295 | + $this->lock($share->getNode()); |
|
| 296 | + } catch (LockedException $e) { |
|
| 297 | + throw new OCSNotFoundException($this->l->t('could not delete share')); |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + if (!$this->canAccessShare($share)) { |
|
| 301 | + throw new OCSNotFoundException($this->l->t('Could not delete share')); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP && |
|
| 305 | + $share->getShareOwner() !== $this->currentUser && |
|
| 306 | + $share->getSharedBy() !== $this->currentUser) { |
|
| 307 | + $this->shareManager->deleteFromSelf($share, $this->currentUser); |
|
| 308 | + } else { |
|
| 309 | + $this->shareManager->deleteShare($share); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return new DataResponse(); |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * @NoAdminRequired |
|
| 317 | + * |
|
| 318 | + * @param string $path |
|
| 319 | + * @param int $permissions |
|
| 320 | + * @param int $shareType |
|
| 321 | + * @param string $shareWith |
|
| 322 | + * @param string $publicUpload |
|
| 323 | + * @param string $password |
|
| 324 | + * @param string $expireDate |
|
| 325 | + * |
|
| 326 | + * @return DataResponse |
|
| 327 | + * @throws OCSNotFoundException |
|
| 328 | + * @throws OCSForbiddenException |
|
| 329 | + * @throws OCSBadRequestException |
|
| 330 | + * @throws OCSException |
|
| 331 | + * |
|
| 332 | + * @suppress PhanUndeclaredClassMethod |
|
| 333 | + */ |
|
| 334 | + public function createShare( |
|
| 335 | + $path = null, |
|
| 336 | + $permissions = null, |
|
| 337 | + $shareType = -1, |
|
| 338 | + $shareWith = null, |
|
| 339 | + $publicUpload = 'false', |
|
| 340 | + $password = '', |
|
| 341 | + $expireDate = '' |
|
| 342 | + ) { |
|
| 343 | + $share = $this->shareManager->newShare(); |
|
| 344 | + |
|
| 345 | + if ($permissions === null) { |
|
| 346 | + $permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + // Verify path |
|
| 350 | + if ($path === null) { |
|
| 351 | + throw new OCSNotFoundException($this->l->t('Please specify a file or folder path')); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 355 | + try { |
|
| 356 | + $path = $userFolder->get($path); |
|
| 357 | + } catch (NotFoundException $e) { |
|
| 358 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + $share->setNode($path); |
|
| 362 | + |
|
| 363 | + try { |
|
| 364 | + $this->lock($share->getNode()); |
|
| 365 | + } catch (LockedException $e) { |
|
| 366 | + throw new OCSNotFoundException($this->l->t('Could not create share')); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ($permissions < 0 || $permissions > Constants::PERMISSION_ALL) { |
|
| 370 | + throw new OCSNotFoundException($this->l->t('invalid permissions')); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // Shares always require read permissions |
|
| 374 | + $permissions |= Constants::PERMISSION_READ; |
|
| 375 | + |
|
| 376 | + if ($path instanceof \OCP\Files\File) { |
|
| 377 | + // Single file shares should never have delete or create permissions |
|
| 378 | + $permissions &= ~Constants::PERMISSION_DELETE; |
|
| 379 | + $permissions &= ~Constants::PERMISSION_CREATE; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /* |
|
| 383 | 383 | * Hack for https://github.com/owncloud/core/issues/22587 |
| 384 | 384 | * We check the permissions via webdav. But the permissions of the mount point |
| 385 | 385 | * do not equal the share permissions. Here we fix that for federated mounts. |
| 386 | 386 | */ |
| 387 | - if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 388 | - $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 392 | - // Valid user is required to share |
|
| 393 | - if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 394 | - throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 395 | - } |
|
| 396 | - $share->setSharedWith($shareWith); |
|
| 397 | - $share->setPermissions($permissions); |
|
| 398 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 399 | - if (!$this->shareManager->allowGroupSharing()) { |
|
| 400 | - throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - // Valid group is required to share |
|
| 404 | - if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 405 | - throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 406 | - } |
|
| 407 | - $share->setSharedWith($shareWith); |
|
| 408 | - $share->setPermissions($permissions); |
|
| 409 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 410 | - //Can we even share links? |
|
| 411 | - if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 412 | - throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /* |
|
| 387 | + if ($path->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
|
| 388 | + $permissions &= ~($permissions & ~$path->getPermissions()); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
| 392 | + // Valid user is required to share |
|
| 393 | + if ($shareWith === null || !$this->userManager->userExists($shareWith)) { |
|
| 394 | + throw new OCSNotFoundException($this->l->t('Please specify a valid user')); |
|
| 395 | + } |
|
| 396 | + $share->setSharedWith($shareWith); |
|
| 397 | + $share->setPermissions($permissions); |
|
| 398 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 399 | + if (!$this->shareManager->allowGroupSharing()) { |
|
| 400 | + throw new OCSNotFoundException($this->l->t('Group sharing is disabled by the administrator')); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + // Valid group is required to share |
|
| 404 | + if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) { |
|
| 405 | + throw new OCSNotFoundException($this->l->t('Please specify a valid group')); |
|
| 406 | + } |
|
| 407 | + $share->setSharedWith($shareWith); |
|
| 408 | + $share->setPermissions($permissions); |
|
| 409 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 410 | + //Can we even share links? |
|
| 411 | + if (!$this->shareManager->shareApiAllowLinks()) { |
|
| 412 | + throw new OCSNotFoundException($this->l->t('Public link sharing is disabled by the administrator')); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /* |
|
| 416 | 416 | * For now we only allow 1 link share. |
| 417 | 417 | * Return the existing link share if this is a duplicate |
| 418 | 418 | */ |
| 419 | - $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 420 | - if (!empty($existingShares)) { |
|
| 421 | - return new DataResponse($this->formatShare($existingShares[0])); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - if ($publicUpload === 'true') { |
|
| 425 | - // Check if public upload is allowed |
|
| 426 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 427 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // Public upload can only be set for folders |
|
| 431 | - if ($path instanceof \OCP\Files\File) { |
|
| 432 | - throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - $share->setPermissions( |
|
| 436 | - Constants::PERMISSION_READ | |
|
| 437 | - Constants::PERMISSION_CREATE | |
|
| 438 | - Constants::PERMISSION_UPDATE | |
|
| 439 | - Constants::PERMISSION_DELETE |
|
| 440 | - ); |
|
| 441 | - } else { |
|
| 442 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - // Set password |
|
| 446 | - if ($password !== '') { |
|
| 447 | - $share->setPassword($password); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - //Expire date |
|
| 451 | - if ($expireDate !== '') { |
|
| 452 | - try { |
|
| 453 | - $expireDate = $this->parseDate($expireDate); |
|
| 454 | - $share->setExpirationDate($expireDate); |
|
| 455 | - } catch (\Exception $e) { |
|
| 456 | - throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 461 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 462 | - throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $share->setSharedWith($shareWith); |
|
| 466 | - $share->setPermissions($permissions); |
|
| 467 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 468 | - if ($share->getNodeType() === 'file') { |
|
| 469 | - $share->setPermissions(Constants::PERMISSION_READ); |
|
| 470 | - } else { |
|
| 471 | - $share->setPermissions($permissions); |
|
| 472 | - } |
|
| 473 | - $share->setSharedWith($shareWith); |
|
| 474 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 475 | - if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
| 476 | - throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
| 480 | - |
|
| 481 | - // Valid circle is required to share |
|
| 482 | - if ($circle === null) { |
|
| 483 | - throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 484 | - } |
|
| 485 | - $share->setSharedWith($shareWith); |
|
| 486 | - $share->setPermissions($permissions); |
|
| 487 | - } else { |
|
| 488 | - throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - $share->setShareType($shareType); |
|
| 492 | - $share->setSharedBy($this->currentUser); |
|
| 493 | - |
|
| 494 | - try { |
|
| 495 | - $share = $this->shareManager->createShare($share); |
|
| 496 | - } catch (GenericShareException $e) { |
|
| 497 | - $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 498 | - throw new OCSException($e->getHint(), $code); |
|
| 499 | - } catch (\Exception $e) { |
|
| 500 | - throw new OCSForbiddenException($e->getMessage(), $e); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $output = $this->formatShare($share); |
|
| 504 | - |
|
| 505 | - return new DataResponse($output); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 510 | - * @param boolean $includeTags |
|
| 511 | - * @return DataResponse |
|
| 512 | - */ |
|
| 513 | - private function getSharedWithMe($node = null, $includeTags) { |
|
| 514 | - |
|
| 515 | - $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 516 | - $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 517 | - $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 518 | - |
|
| 519 | - $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 520 | - |
|
| 521 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 522 | - return $share->getShareOwner() !== $this->currentUser; |
|
| 523 | - }); |
|
| 524 | - |
|
| 525 | - $formatted = []; |
|
| 526 | - foreach ($shares as $share) { |
|
| 527 | - if ($this->canAccessShare($share)) { |
|
| 528 | - try { |
|
| 529 | - $formatted[] = $this->formatShare($share); |
|
| 530 | - } catch (NotFoundException $e) { |
|
| 531 | - // Ignore this share |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - if ($includeTags) { |
|
| 537 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return new DataResponse($formatted); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * @param \OCP\Files\Folder $folder |
|
| 545 | - * @return DataResponse |
|
| 546 | - * @throws OCSBadRequestException |
|
| 547 | - */ |
|
| 548 | - private function getSharesInDir($folder) { |
|
| 549 | - if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 550 | - throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $nodes = $folder->getDirectoryListing(); |
|
| 554 | - /** @var \OCP\Share\IShare[] $shares */ |
|
| 555 | - $shares = []; |
|
| 556 | - foreach ($nodes as $node) { |
|
| 557 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 558 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 559 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 560 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 561 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 562 | - } |
|
| 563 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 564 | - $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - $formatted = []; |
|
| 569 | - foreach ($shares as $share) { |
|
| 570 | - try { |
|
| 571 | - $formatted[] = $this->formatShare($share); |
|
| 572 | - } catch (NotFoundException $e) { |
|
| 573 | - //Ignore this share |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return new DataResponse($formatted); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * The getShares function. |
|
| 582 | - * |
|
| 583 | - * @NoAdminRequired |
|
| 584 | - * |
|
| 585 | - * @param string $shared_with_me |
|
| 586 | - * @param string $reshares |
|
| 587 | - * @param string $subfiles |
|
| 588 | - * @param string $path |
|
| 589 | - * |
|
| 590 | - * - Get shares by the current user |
|
| 591 | - * - Get shares by the current user and reshares (?reshares=true) |
|
| 592 | - * - Get shares with the current user (?shared_with_me=true) |
|
| 593 | - * - Get shares for a specific path (?path=...) |
|
| 594 | - * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 595 | - * |
|
| 596 | - * @return DataResponse |
|
| 597 | - * @throws OCSNotFoundException |
|
| 598 | - */ |
|
| 599 | - public function getShares( |
|
| 600 | - $shared_with_me = 'false', |
|
| 601 | - $reshares = 'false', |
|
| 602 | - $subfiles = 'false', |
|
| 603 | - $path = null, |
|
| 604 | - $include_tags = 'false' |
|
| 605 | - ) { |
|
| 606 | - |
|
| 607 | - if ($path !== null) { |
|
| 608 | - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 609 | - try { |
|
| 610 | - $path = $userFolder->get($path); |
|
| 611 | - $this->lock($path); |
|
| 612 | - } catch (\OCP\Files\NotFoundException $e) { |
|
| 613 | - throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 614 | - } catch (LockedException $e) { |
|
| 615 | - throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 616 | - } |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - if ($shared_with_me === 'true') { |
|
| 620 | - $result = $this->getSharedWithMe($path, $include_tags); |
|
| 621 | - return $result; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - if ($subfiles === 'true') { |
|
| 625 | - $result = $this->getSharesInDir($path); |
|
| 626 | - return $result; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if ($reshares === 'true') { |
|
| 630 | - $reshares = true; |
|
| 631 | - } else { |
|
| 632 | - $reshares = false; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - // Get all shares |
|
| 636 | - $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 637 | - $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 638 | - $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 639 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 640 | - $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 641 | - } else { |
|
| 642 | - $mailShares = []; |
|
| 643 | - } |
|
| 644 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 645 | - $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 646 | - } else { |
|
| 647 | - $circleShares = []; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 651 | - |
|
| 652 | - if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 653 | - $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 654 | - $shares = array_merge($shares, $federatedShares); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - $formatted = []; |
|
| 658 | - foreach ($shares as $share) { |
|
| 659 | - try { |
|
| 660 | - $formatted[] = $this->formatShare($share, $path); |
|
| 661 | - } catch (NotFoundException $e) { |
|
| 662 | - //Ignore share |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - if ($include_tags) { |
|
| 667 | - $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - return new DataResponse($formatted); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * @NoAdminRequired |
|
| 675 | - * |
|
| 676 | - * @param int $id |
|
| 677 | - * @param int $permissions |
|
| 678 | - * @param string $password |
|
| 679 | - * @param string $publicUpload |
|
| 680 | - * @param string $expireDate |
|
| 681 | - * @return DataResponse |
|
| 682 | - * @throws OCSNotFoundException |
|
| 683 | - * @throws OCSBadRequestException |
|
| 684 | - * @throws OCSForbiddenException |
|
| 685 | - */ |
|
| 686 | - public function updateShare( |
|
| 687 | - $id, |
|
| 688 | - $permissions = null, |
|
| 689 | - $password = null, |
|
| 690 | - $publicUpload = null, |
|
| 691 | - $expireDate = null |
|
| 692 | - ) { |
|
| 693 | - try { |
|
| 694 | - $share = $this->getShareById($id); |
|
| 695 | - } catch (ShareNotFound $e) { |
|
| 696 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - $this->lock($share->getNode()); |
|
| 700 | - |
|
| 701 | - if (!$this->canAccessShare($share, false)) { |
|
| 702 | - throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 706 | - throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - /* |
|
| 419 | + $existingShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0); |
|
| 420 | + if (!empty($existingShares)) { |
|
| 421 | + return new DataResponse($this->formatShare($existingShares[0])); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + if ($publicUpload === 'true') { |
|
| 425 | + // Check if public upload is allowed |
|
| 426 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 427 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // Public upload can only be set for folders |
|
| 431 | + if ($path instanceof \OCP\Files\File) { |
|
| 432 | + throw new OCSNotFoundException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + $share->setPermissions( |
|
| 436 | + Constants::PERMISSION_READ | |
|
| 437 | + Constants::PERMISSION_CREATE | |
|
| 438 | + Constants::PERMISSION_UPDATE | |
|
| 439 | + Constants::PERMISSION_DELETE |
|
| 440 | + ); |
|
| 441 | + } else { |
|
| 442 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + // Set password |
|
| 446 | + if ($password !== '') { |
|
| 447 | + $share->setPassword($password); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + //Expire date |
|
| 451 | + if ($expireDate !== '') { |
|
| 452 | + try { |
|
| 453 | + $expireDate = $this->parseDate($expireDate); |
|
| 454 | + $share->setExpirationDate($expireDate); |
|
| 455 | + } catch (\Exception $e) { |
|
| 456 | + throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD')); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
| 461 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 462 | + throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not allow shares from type %s', [$path->getPath(), $shareType])); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $share->setSharedWith($shareWith); |
|
| 466 | + $share->setPermissions($permissions); |
|
| 467 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 468 | + if ($share->getNodeType() === 'file') { |
|
| 469 | + $share->setPermissions(Constants::PERMISSION_READ); |
|
| 470 | + } else { |
|
| 471 | + $share->setPermissions($permissions); |
|
| 472 | + } |
|
| 473 | + $share->setSharedWith($shareWith); |
|
| 474 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 475 | + if (!\OC::$server->getAppManager()->isEnabledForUser('circles') || !class_exists('\OCA\Circles\ShareByCircleProvider')) { |
|
| 476 | + throw new OCSNotFoundException($this->l->t('You cannot share to a Circle if the app is not enabled')); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $circle = \OCA\Circles\Api\v1\Circles::detailsCircle($shareWith); |
|
| 480 | + |
|
| 481 | + // Valid circle is required to share |
|
| 482 | + if ($circle === null) { |
|
| 483 | + throw new OCSNotFoundException($this->l->t('Please specify a valid circle')); |
|
| 484 | + } |
|
| 485 | + $share->setSharedWith($shareWith); |
|
| 486 | + $share->setPermissions($permissions); |
|
| 487 | + } else { |
|
| 488 | + throw new OCSBadRequestException($this->l->t('Unknown share type')); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + $share->setShareType($shareType); |
|
| 492 | + $share->setSharedBy($this->currentUser); |
|
| 493 | + |
|
| 494 | + try { |
|
| 495 | + $share = $this->shareManager->createShare($share); |
|
| 496 | + } catch (GenericShareException $e) { |
|
| 497 | + $code = $e->getCode() === 0 ? 403 : $e->getCode(); |
|
| 498 | + throw new OCSException($e->getHint(), $code); |
|
| 499 | + } catch (\Exception $e) { |
|
| 500 | + throw new OCSForbiddenException($e->getMessage(), $e); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $output = $this->formatShare($share); |
|
| 504 | + |
|
| 505 | + return new DataResponse($output); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * @param \OCP\Files\File|\OCP\Files\Folder $node |
|
| 510 | + * @param boolean $includeTags |
|
| 511 | + * @return DataResponse |
|
| 512 | + */ |
|
| 513 | + private function getSharedWithMe($node = null, $includeTags) { |
|
| 514 | + |
|
| 515 | + $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0); |
|
| 516 | + $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0); |
|
| 517 | + $circleShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $node, -1, 0); |
|
| 518 | + |
|
| 519 | + $shares = array_merge($userShares, $groupShares, $circleShares); |
|
| 520 | + |
|
| 521 | + $shares = array_filter($shares, function (IShare $share) { |
|
| 522 | + return $share->getShareOwner() !== $this->currentUser; |
|
| 523 | + }); |
|
| 524 | + |
|
| 525 | + $formatted = []; |
|
| 526 | + foreach ($shares as $share) { |
|
| 527 | + if ($this->canAccessShare($share)) { |
|
| 528 | + try { |
|
| 529 | + $formatted[] = $this->formatShare($share); |
|
| 530 | + } catch (NotFoundException $e) { |
|
| 531 | + // Ignore this share |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + if ($includeTags) { |
|
| 537 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return new DataResponse($formatted); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * @param \OCP\Files\Folder $folder |
|
| 545 | + * @return DataResponse |
|
| 546 | + * @throws OCSBadRequestException |
|
| 547 | + */ |
|
| 548 | + private function getSharesInDir($folder) { |
|
| 549 | + if (!($folder instanceof \OCP\Files\Folder)) { |
|
| 550 | + throw new OCSBadRequestException($this->l->t('Not a directory')); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $nodes = $folder->getDirectoryListing(); |
|
| 554 | + /** @var \OCP\Share\IShare[] $shares */ |
|
| 555 | + $shares = []; |
|
| 556 | + foreach ($nodes as $node) { |
|
| 557 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
|
| 558 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
|
| 559 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
|
| 560 | + if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 561 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
|
| 562 | + } |
|
| 563 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 564 | + $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $node, false, -1, 0)); |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + $formatted = []; |
|
| 569 | + foreach ($shares as $share) { |
|
| 570 | + try { |
|
| 571 | + $formatted[] = $this->formatShare($share); |
|
| 572 | + } catch (NotFoundException $e) { |
|
| 573 | + //Ignore this share |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return new DataResponse($formatted); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * The getShares function. |
|
| 582 | + * |
|
| 583 | + * @NoAdminRequired |
|
| 584 | + * |
|
| 585 | + * @param string $shared_with_me |
|
| 586 | + * @param string $reshares |
|
| 587 | + * @param string $subfiles |
|
| 588 | + * @param string $path |
|
| 589 | + * |
|
| 590 | + * - Get shares by the current user |
|
| 591 | + * - Get shares by the current user and reshares (?reshares=true) |
|
| 592 | + * - Get shares with the current user (?shared_with_me=true) |
|
| 593 | + * - Get shares for a specific path (?path=...) |
|
| 594 | + * - Get all shares in a folder (?subfiles=true&path=..) |
|
| 595 | + * |
|
| 596 | + * @return DataResponse |
|
| 597 | + * @throws OCSNotFoundException |
|
| 598 | + */ |
|
| 599 | + public function getShares( |
|
| 600 | + $shared_with_me = 'false', |
|
| 601 | + $reshares = 'false', |
|
| 602 | + $subfiles = 'false', |
|
| 603 | + $path = null, |
|
| 604 | + $include_tags = 'false' |
|
| 605 | + ) { |
|
| 606 | + |
|
| 607 | + if ($path !== null) { |
|
| 608 | + $userFolder = $this->rootFolder->getUserFolder($this->currentUser); |
|
| 609 | + try { |
|
| 610 | + $path = $userFolder->get($path); |
|
| 611 | + $this->lock($path); |
|
| 612 | + } catch (\OCP\Files\NotFoundException $e) { |
|
| 613 | + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); |
|
| 614 | + } catch (LockedException $e) { |
|
| 615 | + throw new OCSNotFoundException($this->l->t('Could not lock path')); |
|
| 616 | + } |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + if ($shared_with_me === 'true') { |
|
| 620 | + $result = $this->getSharedWithMe($path, $include_tags); |
|
| 621 | + return $result; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + if ($subfiles === 'true') { |
|
| 625 | + $result = $this->getSharesInDir($path); |
|
| 626 | + return $result; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if ($reshares === 'true') { |
|
| 630 | + $reshares = true; |
|
| 631 | + } else { |
|
| 632 | + $reshares = false; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + // Get all shares |
|
| 636 | + $userShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $path, $reshares, -1, 0); |
|
| 637 | + $groupShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $path, $reshares, -1, 0); |
|
| 638 | + $linkShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $path, $reshares, -1, 0); |
|
| 639 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 640 | + $mailShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $path, $reshares, -1, 0); |
|
| 641 | + } else { |
|
| 642 | + $mailShares = []; |
|
| 643 | + } |
|
| 644 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 645 | + $circleShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_CIRCLE, $path, $reshares, -1, 0); |
|
| 646 | + } else { |
|
| 647 | + $circleShares = []; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + $shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares); |
|
| 651 | + |
|
| 652 | + if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 653 | + $federatedShares = $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0); |
|
| 654 | + $shares = array_merge($shares, $federatedShares); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + $formatted = []; |
|
| 658 | + foreach ($shares as $share) { |
|
| 659 | + try { |
|
| 660 | + $formatted[] = $this->formatShare($share, $path); |
|
| 661 | + } catch (NotFoundException $e) { |
|
| 662 | + //Ignore share |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + if ($include_tags) { |
|
| 667 | + $formatted = Helper::populateTags($formatted, 'file_source', \OC::$server->getTagManager()); |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + return new DataResponse($formatted); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + /** |
|
| 674 | + * @NoAdminRequired |
|
| 675 | + * |
|
| 676 | + * @param int $id |
|
| 677 | + * @param int $permissions |
|
| 678 | + * @param string $password |
|
| 679 | + * @param string $publicUpload |
|
| 680 | + * @param string $expireDate |
|
| 681 | + * @return DataResponse |
|
| 682 | + * @throws OCSNotFoundException |
|
| 683 | + * @throws OCSBadRequestException |
|
| 684 | + * @throws OCSForbiddenException |
|
| 685 | + */ |
|
| 686 | + public function updateShare( |
|
| 687 | + $id, |
|
| 688 | + $permissions = null, |
|
| 689 | + $password = null, |
|
| 690 | + $publicUpload = null, |
|
| 691 | + $expireDate = null |
|
| 692 | + ) { |
|
| 693 | + try { |
|
| 694 | + $share = $this->getShareById($id); |
|
| 695 | + } catch (ShareNotFound $e) { |
|
| 696 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + $this->lock($share->getNode()); |
|
| 700 | + |
|
| 701 | + if (!$this->canAccessShare($share, false)) { |
|
| 702 | + throw new OCSNotFoundException($this->l->t('Wrong share ID, share doesn\'t exist')); |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + if ($permissions === null && $password === null && $publicUpload === null && $expireDate === null) { |
|
| 706 | + throw new OCSBadRequestException($this->l->t('Wrong or no update parameter given')); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + /* |
|
| 710 | 710 | * expirationdate, password and publicUpload only make sense for link shares |
| 711 | 711 | */ |
| 712 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 713 | - |
|
| 714 | - $newPermissions = null; |
|
| 715 | - if ($publicUpload === 'true') { |
|
| 716 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 717 | - } else if ($publicUpload === 'false') { |
|
| 718 | - $newPermissions = Constants::PERMISSION_READ; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - if ($permissions !== null) { |
|
| 722 | - $newPermissions = (int)$permissions; |
|
| 723 | - $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - if ($newPermissions !== null && |
|
| 727 | - !in_array($newPermissions, [ |
|
| 728 | - Constants::PERMISSION_READ, |
|
| 729 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
| 730 | - Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
| 731 | - Constants::PERMISSION_CREATE, // hidden file list |
|
| 732 | - Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 733 | - ]) |
|
| 734 | - ) { |
|
| 735 | - throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - if ( |
|
| 739 | - // legacy |
|
| 740 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
| 741 | - // correct |
|
| 742 | - $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 743 | - ) { |
|
| 744 | - if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 745 | - throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 749 | - throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - // normalize to correct public upload permissions |
|
| 753 | - $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ($newPermissions !== null) { |
|
| 757 | - $share->setPermissions($newPermissions); |
|
| 758 | - $permissions = $newPermissions; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - if ($expireDate === '') { |
|
| 762 | - $share->setExpirationDate(null); |
|
| 763 | - } else if ($expireDate !== null) { |
|
| 764 | - try { |
|
| 765 | - $expireDate = $this->parseDate($expireDate); |
|
| 766 | - } catch (\Exception $e) { |
|
| 767 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 768 | - } |
|
| 769 | - $share->setExpirationDate($expireDate); |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - if ($password === '') { |
|
| 773 | - $share->setPassword(null); |
|
| 774 | - } else if ($password !== null) { |
|
| 775 | - $share->setPassword($password); |
|
| 776 | - } |
|
| 777 | - |
|
| 778 | - } else { |
|
| 779 | - if ($permissions !== null) { |
|
| 780 | - $permissions = (int)$permissions; |
|
| 781 | - $share->setPermissions($permissions); |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 785 | - if ($password === '') { |
|
| 786 | - $share->setPassword(null); |
|
| 787 | - } else if ($password !== null) { |
|
| 788 | - $share->setPassword($password); |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - if ($expireDate === '') { |
|
| 793 | - $share->setExpirationDate(null); |
|
| 794 | - } else if ($expireDate !== null) { |
|
| 795 | - try { |
|
| 796 | - $expireDate = $this->parseDate($expireDate); |
|
| 797 | - } catch (\Exception $e) { |
|
| 798 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 799 | - } |
|
| 800 | - $share->setExpirationDate($expireDate); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 806 | - /* Check if this is an incomming share */ |
|
| 807 | - $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 808 | - $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 809 | - |
|
| 810 | - /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 811 | - if (!empty($incomingShares)) { |
|
| 812 | - $maxPermissions = 0; |
|
| 813 | - foreach ($incomingShares as $incomingShare) { |
|
| 814 | - $maxPermissions |= $incomingShare->getPermissions(); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - if ($share->getPermissions() & ~$maxPermissions) { |
|
| 818 | - throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - try { |
|
| 825 | - $share = $this->shareManager->updateShare($share); |
|
| 826 | - } catch (\Exception $e) { |
|
| 827 | - throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return new DataResponse($this->formatShare($share)); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - /** |
|
| 834 | - * @param \OCP\Share\IShare $share |
|
| 835 | - * @return bool |
|
| 836 | - */ |
|
| 837 | - protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 838 | - // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 839 | - if ($share->getPermissions() === 0) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - // Owner of the file and the sharer of the file can always get share |
|
| 844 | - if ($share->getShareOwner() === $this->currentUser || |
|
| 845 | - $share->getSharedBy() === $this->currentUser |
|
| 846 | - ) { |
|
| 847 | - return true; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // If the share is shared with you (or a group you are a member of) |
|
| 851 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 852 | - $share->getSharedWith() === $this->currentUser |
|
| 853 | - ) { |
|
| 854 | - return true; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 858 | - $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 859 | - $user = $this->userManager->get($this->currentUser); |
|
| 860 | - if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 861 | - return true; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 866 | - // TODO: have a sanity check like above? |
|
| 867 | - return true; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - return false; |
|
| 871 | - } |
|
| 872 | - |
|
| 873 | - /** |
|
| 874 | - * Make sure that the passed date is valid ISO 8601 |
|
| 875 | - * So YYYY-MM-DD |
|
| 876 | - * If not throw an exception |
|
| 877 | - * |
|
| 878 | - * @param string $expireDate |
|
| 879 | - * |
|
| 880 | - * @throws \Exception |
|
| 881 | - * @return \DateTime |
|
| 882 | - */ |
|
| 883 | - private function parseDate($expireDate) { |
|
| 884 | - try { |
|
| 885 | - $date = new \DateTime($expireDate); |
|
| 886 | - } catch (\Exception $e) { |
|
| 887 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - if ($date === false) { |
|
| 891 | - throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - $date->setTime(0, 0, 0); |
|
| 895 | - |
|
| 896 | - return $date; |
|
| 897 | - } |
|
| 898 | - |
|
| 899 | - /** |
|
| 900 | - * Since we have multiple providers but the OCS Share API v1 does |
|
| 901 | - * not support this we need to check all backends. |
|
| 902 | - * |
|
| 903 | - * @param string $id |
|
| 904 | - * @return \OCP\Share\IShare |
|
| 905 | - * @throws ShareNotFound |
|
| 906 | - */ |
|
| 907 | - private function getShareById($id) { |
|
| 908 | - $share = null; |
|
| 909 | - |
|
| 910 | - // First check if it is an internal share. |
|
| 911 | - try { |
|
| 912 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 913 | - return $share; |
|
| 914 | - } catch (ShareNotFound $e) { |
|
| 915 | - // Do nothing, just try the other share type |
|
| 916 | - } |
|
| 917 | - |
|
| 918 | - |
|
| 919 | - try { |
|
| 920 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 921 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 922 | - return $share; |
|
| 923 | - } |
|
| 924 | - } catch (ShareNotFound $e) { |
|
| 925 | - // Do nothing, just try the other share type |
|
| 926 | - } |
|
| 927 | - |
|
| 928 | - try { |
|
| 929 | - if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 930 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 931 | - return $share; |
|
| 932 | - } |
|
| 933 | - } catch (ShareNotFound $e) { |
|
| 934 | - // Do nothing, just try the other share type |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 938 | - throw new ShareNotFound(); |
|
| 939 | - } |
|
| 940 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 941 | - |
|
| 942 | - return $share; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - /** |
|
| 946 | - * Lock a Node |
|
| 947 | - * |
|
| 948 | - * @param \OCP\Files\Node $node |
|
| 949 | - */ |
|
| 950 | - private function lock(\OCP\Files\Node $node) { |
|
| 951 | - $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 952 | - $this->lockedNode = $node; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - /** |
|
| 956 | - * Cleanup the remaining locks |
|
| 957 | - */ |
|
| 958 | - public function cleanup() { |
|
| 959 | - if ($this->lockedNode !== null) { |
|
| 960 | - $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 961 | - } |
|
| 962 | - } |
|
| 712 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
| 713 | + |
|
| 714 | + $newPermissions = null; |
|
| 715 | + if ($publicUpload === 'true') { |
|
| 716 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 717 | + } else if ($publicUpload === 'false') { |
|
| 718 | + $newPermissions = Constants::PERMISSION_READ; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + if ($permissions !== null) { |
|
| 722 | + $newPermissions = (int)$permissions; |
|
| 723 | + $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + if ($newPermissions !== null && |
|
| 727 | + !in_array($newPermissions, [ |
|
| 728 | + Constants::PERMISSION_READ, |
|
| 729 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE, // legacy |
|
| 730 | + Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE, // correct |
|
| 731 | + Constants::PERMISSION_CREATE, // hidden file list |
|
| 732 | + Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, // allow to edit single files |
|
| 733 | + ]) |
|
| 734 | + ) { |
|
| 735 | + throw new OCSBadRequestException($this->l->t('Can\'t change permissions for public share links')); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + if ( |
|
| 739 | + // legacy |
|
| 740 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE) || |
|
| 741 | + // correct |
|
| 742 | + $newPermissions === (Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE) |
|
| 743 | + ) { |
|
| 744 | + if (!$this->shareManager->shareApiLinkAllowPublicUpload()) { |
|
| 745 | + throw new OCSForbiddenException($this->l->t('Public upload disabled by the administrator')); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if (!($share->getNode() instanceof \OCP\Files\Folder)) { |
|
| 749 | + throw new OCSBadRequestException($this->l->t('Public upload is only possible for publicly shared folders')); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + // normalize to correct public upload permissions |
|
| 753 | + $newPermissions = Constants::PERMISSION_READ | Constants::PERMISSION_CREATE | Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ($newPermissions !== null) { |
|
| 757 | + $share->setPermissions($newPermissions); |
|
| 758 | + $permissions = $newPermissions; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + if ($expireDate === '') { |
|
| 762 | + $share->setExpirationDate(null); |
|
| 763 | + } else if ($expireDate !== null) { |
|
| 764 | + try { |
|
| 765 | + $expireDate = $this->parseDate($expireDate); |
|
| 766 | + } catch (\Exception $e) { |
|
| 767 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 768 | + } |
|
| 769 | + $share->setExpirationDate($expireDate); |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + if ($password === '') { |
|
| 773 | + $share->setPassword(null); |
|
| 774 | + } else if ($password !== null) { |
|
| 775 | + $share->setPassword($password); |
|
| 776 | + } |
|
| 777 | + |
|
| 778 | + } else { |
|
| 779 | + if ($permissions !== null) { |
|
| 780 | + $permissions = (int)$permissions; |
|
| 781 | + $share->setPermissions($permissions); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
| 785 | + if ($password === '') { |
|
| 786 | + $share->setPassword(null); |
|
| 787 | + } else if ($password !== null) { |
|
| 788 | + $share->setPassword($password); |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + if ($expireDate === '') { |
|
| 793 | + $share->setExpirationDate(null); |
|
| 794 | + } else if ($expireDate !== null) { |
|
| 795 | + try { |
|
| 796 | + $expireDate = $this->parseDate($expireDate); |
|
| 797 | + } catch (\Exception $e) { |
|
| 798 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 799 | + } |
|
| 800 | + $share->setExpirationDate($expireDate); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) { |
|
| 806 | + /* Check if this is an incomming share */ |
|
| 807 | + $incomingShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $share->getNode(), -1, 0); |
|
| 808 | + $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0)); |
|
| 809 | + |
|
| 810 | + /** @var \OCP\Share\IShare[] $incomingShares */ |
|
| 811 | + if (!empty($incomingShares)) { |
|
| 812 | + $maxPermissions = 0; |
|
| 813 | + foreach ($incomingShares as $incomingShare) { |
|
| 814 | + $maxPermissions |= $incomingShare->getPermissions(); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + if ($share->getPermissions() & ~$maxPermissions) { |
|
| 818 | + throw new OCSNotFoundException($this->l->t('Cannot increase permissions')); |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + try { |
|
| 825 | + $share = $this->shareManager->updateShare($share); |
|
| 826 | + } catch (\Exception $e) { |
|
| 827 | + throw new OCSBadRequestException($e->getMessage(), $e); |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return new DataResponse($this->formatShare($share)); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + /** |
|
| 834 | + * @param \OCP\Share\IShare $share |
|
| 835 | + * @return bool |
|
| 836 | + */ |
|
| 837 | + protected function canAccessShare(\OCP\Share\IShare $share, $checkGroups = true) { |
|
| 838 | + // A file with permissions 0 can't be accessed by us. So Don't show it |
|
| 839 | + if ($share->getPermissions() === 0) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + // Owner of the file and the sharer of the file can always get share |
|
| 844 | + if ($share->getShareOwner() === $this->currentUser || |
|
| 845 | + $share->getSharedBy() === $this->currentUser |
|
| 846 | + ) { |
|
| 847 | + return true; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + // If the share is shared with you (or a group you are a member of) |
|
| 851 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 852 | + $share->getSharedWith() === $this->currentUser |
|
| 853 | + ) { |
|
| 854 | + return true; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + if ($checkGroups && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
| 858 | + $sharedWith = $this->groupManager->get($share->getSharedWith()); |
|
| 859 | + $user = $this->userManager->get($this->currentUser); |
|
| 860 | + if ($user !== null && $sharedWith !== null && $sharedWith->inGroup($user)) { |
|
| 861 | + return true; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
|
| 866 | + // TODO: have a sanity check like above? |
|
| 867 | + return true; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + return false; |
|
| 871 | + } |
|
| 872 | + |
|
| 873 | + /** |
|
| 874 | + * Make sure that the passed date is valid ISO 8601 |
|
| 875 | + * So YYYY-MM-DD |
|
| 876 | + * If not throw an exception |
|
| 877 | + * |
|
| 878 | + * @param string $expireDate |
|
| 879 | + * |
|
| 880 | + * @throws \Exception |
|
| 881 | + * @return \DateTime |
|
| 882 | + */ |
|
| 883 | + private function parseDate($expireDate) { |
|
| 884 | + try { |
|
| 885 | + $date = new \DateTime($expireDate); |
|
| 886 | + } catch (\Exception $e) { |
|
| 887 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + if ($date === false) { |
|
| 891 | + throw new \Exception('Invalid date. Format must be YYYY-MM-DD'); |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + $date->setTime(0, 0, 0); |
|
| 895 | + |
|
| 896 | + return $date; |
|
| 897 | + } |
|
| 898 | + |
|
| 899 | + /** |
|
| 900 | + * Since we have multiple providers but the OCS Share API v1 does |
|
| 901 | + * not support this we need to check all backends. |
|
| 902 | + * |
|
| 903 | + * @param string $id |
|
| 904 | + * @return \OCP\Share\IShare |
|
| 905 | + * @throws ShareNotFound |
|
| 906 | + */ |
|
| 907 | + private function getShareById($id) { |
|
| 908 | + $share = null; |
|
| 909 | + |
|
| 910 | + // First check if it is an internal share. |
|
| 911 | + try { |
|
| 912 | + $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 913 | + return $share; |
|
| 914 | + } catch (ShareNotFound $e) { |
|
| 915 | + // Do nothing, just try the other share type |
|
| 916 | + } |
|
| 917 | + |
|
| 918 | + |
|
| 919 | + try { |
|
| 920 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
|
| 921 | + $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 922 | + return $share; |
|
| 923 | + } |
|
| 924 | + } catch (ShareNotFound $e) { |
|
| 925 | + // Do nothing, just try the other share type |
|
| 926 | + } |
|
| 927 | + |
|
| 928 | + try { |
|
| 929 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 930 | + $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 931 | + return $share; |
|
| 932 | + } |
|
| 933 | + } catch (ShareNotFound $e) { |
|
| 934 | + // Do nothing, just try the other share type |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
|
| 938 | + throw new ShareNotFound(); |
|
| 939 | + } |
|
| 940 | + $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 941 | + |
|
| 942 | + return $share; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + /** |
|
| 946 | + * Lock a Node |
|
| 947 | + * |
|
| 948 | + * @param \OCP\Files\Node $node |
|
| 949 | + */ |
|
| 950 | + private function lock(\OCP\Files\Node $node) { |
|
| 951 | + $node->lock(ILockingProvider::LOCK_SHARED); |
|
| 952 | + $this->lockedNode = $node; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + /** |
|
| 956 | + * Cleanup the remaining locks |
|
| 957 | + */ |
|
| 958 | + public function cleanup() { |
|
| 959 | + if ($this->lockedNode !== null) { |
|
| 960 | + $this->lockedNode->unlock(ILockingProvider::LOCK_SHARED); |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | 963 | } |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | // "name (type, owner) [id]", depending on the Circles app version. |
| 212 | 212 | $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); |
| 213 | 213 | |
| 214 | - $displayNameLength = ($hasCircleId? strrpos($share->getSharedWith(), ' '): strlen($share->getSharedWith())); |
|
| 214 | + $displayNameLength = ($hasCircleId ? strrpos($share->getSharedWith(), ' ') : strlen($share->getSharedWith())); |
|
| 215 | 215 | $result['share_with_displayname'] = substr($share->getSharedWith(), 0, $displayNameLength); |
| 216 | 216 | |
| 217 | - $shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0); |
|
| 218 | - $shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' ')); |
|
| 217 | + $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); |
|
| 218 | + $shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' ')); |
|
| 219 | 219 | $result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); |
| 220 | 220 | } |
| 221 | 221 | |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | // FIXME: If we inject the contacts manager it gets initialized bofore any address books are registered |
| 238 | 238 | $result = \OC::$server->getContactsManager()->search($query, [$property]); |
| 239 | 239 | foreach ($result as $r) { |
| 240 | - foreach($r[$property] as $value) { |
|
| 240 | + foreach ($r[$property] as $value) { |
|
| 241 | 241 | if ($value === $query) { |
| 242 | 242 | return $r['FN']; |
| 243 | 243 | } |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | |
| 519 | 519 | $shares = array_merge($userShares, $groupShares, $circleShares); |
| 520 | 520 | |
| 521 | - $shares = array_filter($shares, function (IShare $share) { |
|
| 521 | + $shares = array_filter($shares, function(IShare $share) { |
|
| 522 | 522 | return $share->getShareOwner() !== $this->currentUser; |
| 523 | 523 | }); |
| 524 | 524 | |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, false, -1, 0)); |
| 558 | 558 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, false, -1, 0)); |
| 559 | 559 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_LINK, $node, false, -1, 0)); |
| 560 | - if($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 560 | + if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
|
| 561 | 561 | $shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, \OCP\Share::SHARE_TYPE_EMAIL, $node, false, -1, 0)); |
| 562 | 562 | } |
| 563 | 563 | if ($this->shareManager->outgoingServer2ServerSharesAllowed()) { |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | if ($permissions !== null) { |
| 722 | - $newPermissions = (int)$permissions; |
|
| 722 | + $newPermissions = (int) $permissions; |
|
| 723 | 723 | $newPermissions = $newPermissions & ~Constants::PERMISSION_SHARE; |
| 724 | 724 | } |
| 725 | 725 | |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | } else { |
| 779 | 779 | if ($permissions !== null) { |
| 780 | - $permissions = (int)$permissions; |
|
| 780 | + $permissions = (int) $permissions; |
|
| 781 | 781 | $share->setPermissions($permissions); |
| 782 | 782 | } |
| 783 | 783 | |
@@ -909,7 +909,7 @@ discard block |
||
| 909 | 909 | |
| 910 | 910 | // First check if it is an internal share. |
| 911 | 911 | try { |
| 912 | - $share = $this->shareManager->getShareById('ocinternal:' . $id); |
|
| 912 | + $share = $this->shareManager->getShareById('ocinternal:'.$id); |
|
| 913 | 913 | return $share; |
| 914 | 914 | } catch (ShareNotFound $e) { |
| 915 | 915 | // Do nothing, just try the other share type |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | try { |
| 920 | 920 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_CIRCLE)) { |
| 921 | - $share = $this->shareManager->getShareById('ocCircleShare:' . $id); |
|
| 921 | + $share = $this->shareManager->getShareById('ocCircleShare:'.$id); |
|
| 922 | 922 | return $share; |
| 923 | 923 | } |
| 924 | 924 | } catch (ShareNotFound $e) { |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | |
| 928 | 928 | try { |
| 929 | 929 | if ($this->shareManager->shareProviderExists(\OCP\Share::SHARE_TYPE_EMAIL)) { |
| 930 | - $share = $this->shareManager->getShareById('ocMailShare:' . $id); |
|
| 930 | + $share = $this->shareManager->getShareById('ocMailShare:'.$id); |
|
| 931 | 931 | return $share; |
| 932 | 932 | } |
| 933 | 933 | } catch (ShareNotFound $e) { |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) { |
| 938 | 938 | throw new ShareNotFound(); |
| 939 | 939 | } |
| 940 | - $share = $this->shareManager->getShareById('ocFederatedSharing:' . $id); |
|
| 940 | + $share = $this->shareManager->getShareById('ocFederatedSharing:'.$id); |
|
| 941 | 941 | |
| 942 | 942 | return $share; |
| 943 | 943 | } |