Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Manager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Manager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 58 | class Manager implements IManager { |
||
| 59 | |||
| 60 | /** @var IProviderFactory */ |
||
| 61 | private $factory; |
||
| 62 | /** @var ILogger */ |
||
| 63 | private $logger; |
||
| 64 | /** @var IConfig */ |
||
| 65 | private $config; |
||
| 66 | /** @var ISecureRandom */ |
||
| 67 | private $secureRandom; |
||
| 68 | /** @var IHasher */ |
||
| 69 | private $hasher; |
||
| 70 | /** @var IMountManager */ |
||
| 71 | private $mountManager; |
||
| 72 | /** @var IGroupManager */ |
||
| 73 | private $groupManager; |
||
| 74 | /** @var IL10N */ |
||
| 75 | private $l; |
||
| 76 | /** @var IUserManager */ |
||
| 77 | private $userManager; |
||
| 78 | /** @var IRootFolder */ |
||
| 79 | private $rootFolder; |
||
| 80 | /** @var CappedMemoryCache */ |
||
| 81 | private $sharingDisabledForUsersCache; |
||
| 82 | /** @var EventDispatcher */ |
||
| 83 | private $eventDispatcher; |
||
| 84 | |||
| 85 | |||
| 86 | /** |
||
| 87 | * Manager constructor. |
||
| 88 | * |
||
| 89 | * @param ILogger $logger |
||
| 90 | * @param IConfig $config |
||
| 91 | * @param ISecureRandom $secureRandom |
||
| 92 | * @param IHasher $hasher |
||
| 93 | * @param IMountManager $mountManager |
||
| 94 | * @param IGroupManager $groupManager |
||
| 95 | * @param IL10N $l |
||
| 96 | * @param IProviderFactory $factory |
||
| 97 | * @param IUserManager $userManager |
||
| 98 | * @param IRootFolder $rootFolder |
||
| 99 | * @param EventDispatcher $eventDispatcher |
||
| 100 | */ |
||
| 101 | public function __construct( |
||
| 102 | ILogger $logger, |
||
| 103 | IConfig $config, |
||
| 104 | ISecureRandom $secureRandom, |
||
| 105 | IHasher $hasher, |
||
| 106 | IMountManager $mountManager, |
||
| 107 | IGroupManager $groupManager, |
||
| 108 | IL10N $l, |
||
| 109 | IProviderFactory $factory, |
||
| 110 | IUserManager $userManager, |
||
| 111 | IRootFolder $rootFolder, |
||
| 112 | EventDispatcher $eventDispatcher |
||
| 113 | ) { |
||
| 114 | $this->logger = $logger; |
||
| 115 | $this->config = $config; |
||
| 116 | $this->secureRandom = $secureRandom; |
||
| 117 | $this->hasher = $hasher; |
||
| 118 | $this->mountManager = $mountManager; |
||
| 119 | $this->groupManager = $groupManager; |
||
| 120 | $this->l = $l; |
||
| 121 | $this->factory = $factory; |
||
| 122 | $this->userManager = $userManager; |
||
| 123 | $this->rootFolder = $rootFolder; |
||
| 124 | $this->eventDispatcher = $eventDispatcher; |
||
| 125 | $this->sharingDisabledForUsersCache = new CappedMemoryCache(); |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Convert from a full share id to a tuple (providerId, shareId) |
||
| 130 | * |
||
| 131 | * @param string $id |
||
| 132 | * @return string[] |
||
| 133 | */ |
||
| 134 | private function splitFullId($id) { |
||
| 135 | return explode(':', $id, 2); |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Verify if a password meets all requirements |
||
| 140 | * |
||
| 141 | * @param string $password |
||
| 142 | * @throws \Exception |
||
| 143 | */ |
||
| 144 | protected function verifyPassword($password) { |
||
| 145 | if ($password === null) { |
||
| 146 | // No password is set, check if this is allowed. |
||
| 147 | if ($this->shareApiLinkEnforcePassword()) { |
||
| 148 | throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
||
| 149 | } |
||
| 150 | |||
| 151 | return; |
||
| 152 | } |
||
| 153 | |||
| 154 | // Let others verify the password |
||
| 155 | try { |
||
| 156 | $event = new GenericEvent($password); |
||
| 157 | $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
||
| 158 | } catch (HintException $e) { |
||
| 159 | throw new \Exception($e->getHint()); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Check for generic requirements before creating a share |
||
| 165 | * |
||
| 166 | * @param \OCP\Share\IShare $share |
||
| 167 | * @throws \InvalidArgumentException |
||
| 168 | * @throws GenericShareException |
||
| 169 | */ |
||
| 170 | protected function generalCreateChecks(\OCP\Share\IShare $share) { |
||
| 171 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
||
| 172 | // We expect a valid user as sharedWith for user shares |
||
| 173 | if (!$this->userManager->userExists($share->getSharedWith())) { |
||
| 174 | throw new \InvalidArgumentException('SharedWith is not a valid user'); |
||
| 175 | } |
||
| 176 | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
||
| 177 | // We expect a valid group as sharedWith for group shares |
||
| 178 | if (!$this->groupManager->groupExists($share->getSharedWith())) { |
||
| 179 | throw new \InvalidArgumentException('SharedWith is not a valid group'); |
||
| 180 | } |
||
| 181 | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
||
| 182 | if ($share->getSharedWith() !== null) { |
||
| 183 | throw new \InvalidArgumentException('SharedWith should be empty'); |
||
| 184 | } |
||
| 185 | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
||
| 186 | if ($share->getSharedWith() === null) { |
||
| 187 | throw new \InvalidArgumentException('SharedWith should not be empty'); |
||
| 188 | } |
||
| 189 | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
||
| 190 | if ($share->getSharedWith() === null) { |
||
| 191 | throw new \InvalidArgumentException('SharedWith should not be empty'); |
||
| 192 | } |
||
| 193 | } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) { |
||
| 194 | $circle = \OCA\Circles\Api\Circles::detailsCircle($share->getSharedWith()); |
||
| 195 | if ($circle === null) { |
||
| 196 | throw new \InvalidArgumentException('SharedWith is not a valid circle'); |
||
| 197 | } |
||
| 198 | } else { |
||
| 199 | // We can't handle other types yet |
||
| 200 | throw new \InvalidArgumentException('unknown share type'); |
||
| 201 | } |
||
| 202 | |||
| 203 | // Verify the initiator of the share is set |
||
| 204 | if ($share->getSharedBy() === null) { |
||
| 205 | throw new \InvalidArgumentException('SharedBy should be set'); |
||
| 206 | } |
||
| 207 | |||
| 208 | // Cannot share with yourself |
||
| 209 | View Code Duplication | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
| 210 | $share->getSharedWith() === $share->getSharedBy()) { |
||
| 211 | throw new \InvalidArgumentException('Can\'t share with yourself'); |
||
| 212 | } |
||
| 213 | |||
| 214 | // The path should be set |
||
| 215 | if ($share->getNode() === null) { |
||
| 216 | throw new \InvalidArgumentException('Path should be set'); |
||
| 217 | } |
||
| 218 | |||
| 219 | // And it should be a file or a folder |
||
| 220 | if (!($share->getNode() instanceof \OCP\Files\File) && |
||
| 221 | !($share->getNode() instanceof \OCP\Files\Folder)) { |
||
| 222 | throw new \InvalidArgumentException('Path should be either a file or a folder'); |
||
| 223 | } |
||
| 224 | |||
| 225 | // And you can't share your rootfolder |
||
| 226 | if ($this->userManager->userExists($share->getSharedBy())) { |
||
| 227 | $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath(); |
||
| 228 | } else { |
||
| 229 | $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath(); |
||
| 230 | } |
||
| 231 | if ($sharedPath === $share->getNode()->getPath()) { |
||
| 232 | throw new \InvalidArgumentException('You can\'t share your root folder'); |
||
| 233 | } |
||
| 234 | |||
| 235 | // Check if we actually have share permissions |
||
| 236 | View Code Duplication | if (!$share->getNode()->isShareable()) { |
|
| 237 | $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]); |
||
| 238 | throw new GenericShareException($message_t, $message_t, 404); |
||
| 239 | } |
||
| 240 | |||
| 241 | // Permissions should be set |
||
| 242 | if ($share->getPermissions() === null) { |
||
| 243 | throw new \InvalidArgumentException('A share requires permissions'); |
||
| 244 | } |
||
| 245 | |||
| 246 | /* |
||
| 247 | * Quick fix for #23536 |
||
| 248 | * Non moveable mount points do not have update and delete permissions |
||
| 249 | * while we 'most likely' do have that on the storage. |
||
| 250 | */ |
||
| 251 | $permissions = $share->getNode()->getPermissions(); |
||
| 252 | $mount = $share->getNode()->getMountPoint(); |
||
| 253 | if (!($mount instanceof MoveableMount)) { |
||
| 254 | $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
||
| 255 | } |
||
| 256 | |||
| 257 | // Check that we do not share with more permissions than we have |
||
| 258 | View Code Duplication | if ($share->getPermissions() & ~$permissions) { |
|
| 259 | $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]); |
||
| 260 | throw new GenericShareException($message_t, $message_t, 404); |
||
| 261 | } |
||
| 262 | |||
| 263 | |||
| 264 | // Check that read permissions are always set |
||
| 265 | // Link shares are allowed to have no read permissions to allow upload to hidden folders |
||
| 266 | if ($share->getShareType() !== \OCP\Share::SHARE_TYPE_LINK && |
||
| 267 | ($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) { |
||
| 268 | throw new \InvalidArgumentException('Shares need at least read permissions'); |
||
| 269 | } |
||
| 270 | |||
| 271 | if ($share->getNode() instanceof \OCP\Files\File) { |
||
| 272 | View Code Duplication | if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
| 273 | $message_t = $this->l->t('Files can\'t be shared with delete permissions'); |
||
| 274 | throw new GenericShareException($message_t); |
||
| 275 | } |
||
| 276 | View Code Duplication | if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
| 277 | $message_t = $this->l->t('Files can\'t be shared with create permissions'); |
||
| 278 | throw new GenericShareException($message_t); |
||
| 279 | } |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Validate if the expiration date fits the system settings |
||
| 285 | * |
||
| 286 | * @param \OCP\Share\IShare $share The share to validate the expiration date of |
||
| 287 | * @return \OCP\Share\IShare The modified share object |
||
| 288 | * @throws GenericShareException |
||
| 289 | * @throws \InvalidArgumentException |
||
| 290 | * @throws \Exception |
||
| 291 | */ |
||
| 292 | protected function validateExpirationDate(\OCP\Share\IShare $share) { |
||
| 293 | |||
| 294 | $expirationDate = $share->getExpirationDate(); |
||
| 295 | |||
| 296 | if ($expirationDate !== null) { |
||
| 297 | //Make sure the expiration date is a date |
||
| 298 | $expirationDate->setTime(0, 0, 0); |
||
| 299 | |||
| 300 | $date = new \DateTime(); |
||
| 301 | $date->setTime(0, 0, 0); |
||
| 302 | View Code Duplication | if ($date >= $expirationDate) { |
|
| 303 | $message = $this->l->t('Expiration date is in the past'); |
||
| 304 | throw new GenericShareException($message, $message, 404); |
||
| 305 | } |
||
| 306 | } |
||
| 307 | |||
| 308 | // If expiredate is empty set a default one if there is a default |
||
| 309 | $fullId = null; |
||
| 310 | try { |
||
| 311 | $fullId = $share->getFullId(); |
||
| 312 | } catch (\UnexpectedValueException $e) { |
||
| 313 | // This is a new share |
||
| 314 | } |
||
| 315 | |||
| 316 | if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) { |
||
| 317 | $expirationDate = new \DateTime(); |
||
| 318 | $expirationDate->setTime(0,0,0); |
||
| 319 | $expirationDate->add(new \DateInterval('P'.$this->shareApiLinkDefaultExpireDays().'D')); |
||
| 320 | } |
||
| 321 | |||
| 322 | // If we enforce the expiration date check that is does not exceed |
||
| 323 | if ($this->shareApiLinkDefaultExpireDateEnforced()) { |
||
| 324 | if ($expirationDate === null) { |
||
| 325 | throw new \InvalidArgumentException('Expiration date is enforced'); |
||
| 326 | } |
||
| 327 | |||
| 328 | $date = new \DateTime(); |
||
| 329 | $date->setTime(0, 0, 0); |
||
| 330 | $date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D')); |
||
| 331 | View Code Duplication | if ($date < $expirationDate) { |
|
| 332 | $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]); |
||
| 333 | throw new GenericShareException($message, $message, 404); |
||
| 334 | } |
||
| 335 | } |
||
| 336 | |||
| 337 | $accepted = true; |
||
| 338 | $message = ''; |
||
| 339 | \OCP\Util::emitHook('\OC\Share', 'verifyExpirationDate', [ |
||
| 340 | 'expirationDate' => &$expirationDate, |
||
| 341 | 'accepted' => &$accepted, |
||
| 342 | 'message' => &$message, |
||
| 343 | 'passwordSet' => $share->getPassword() !== null, |
||
| 344 | ]); |
||
| 345 | |||
| 346 | if (!$accepted) { |
||
| 347 | throw new \Exception($message); |
||
| 348 | } |
||
| 349 | |||
| 350 | $share->setExpirationDate($expirationDate); |
||
| 351 | |||
| 352 | return $share; |
||
| 353 | } |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Check for pre share requirements for user shares |
||
| 357 | * |
||
| 358 | * @param \OCP\Share\IShare $share |
||
| 359 | * @throws \Exception |
||
| 360 | */ |
||
| 361 | protected function userCreateChecks(\OCP\Share\IShare $share) { |
||
| 362 | // Check if we can share with group members only |
||
| 363 | if ($this->shareWithGroupMembersOnly()) { |
||
| 364 | $sharedBy = $this->userManager->get($share->getSharedBy()); |
||
| 365 | $sharedWith = $this->userManager->get($share->getSharedWith()); |
||
| 366 | // Verify we can share with this user |
||
| 367 | $groups = array_intersect( |
||
| 368 | $this->groupManager->getUserGroupIds($sharedBy), |
||
|
|
|||
| 369 | $this->groupManager->getUserGroupIds($sharedWith) |
||
| 370 | ); |
||
| 371 | if (empty($groups)) { |
||
| 372 | throw new \Exception('Only sharing with group members is allowed'); |
||
| 373 | } |
||
| 374 | } |
||
| 375 | |||
| 376 | /* |
||
| 377 | * TODO: Could be costly, fix |
||
| 378 | * |
||
| 379 | * Also this is not what we want in the future.. then we want to squash identical shares. |
||
| 380 | */ |
||
| 381 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER); |
||
| 382 | $existingShares = $provider->getSharesByPath($share->getNode()); |
||
| 383 | foreach($existingShares as $existingShare) { |
||
| 384 | // Ignore if it is the same share |
||
| 385 | try { |
||
| 386 | if ($existingShare->getFullId() === $share->getFullId()) { |
||
| 387 | continue; |
||
| 388 | } |
||
| 389 | } catch (\UnexpectedValueException $e) { |
||
| 390 | //Shares are not identical |
||
| 391 | } |
||
| 392 | |||
| 393 | // Identical share already existst |
||
| 394 | if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
||
| 395 | throw new \Exception('Path already shared with this user'); |
||
| 396 | } |
||
| 397 | |||
| 398 | // The share is already shared with this user via a group share |
||
| 399 | if ($existingShare->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
||
| 400 | $group = $this->groupManager->get($existingShare->getSharedWith()); |
||
| 401 | if (!is_null($group)) { |
||
| 402 | $user = $this->userManager->get($share->getSharedWith()); |
||
| 403 | |||
| 404 | if ($group->inGroup($user) && $existingShare->getShareOwner() !== $share->getShareOwner()) { |
||
| 405 | throw new \Exception('Path already shared with this user'); |
||
| 406 | } |
||
| 407 | } |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Check for pre share requirements for group shares |
||
| 414 | * |
||
| 415 | * @param \OCP\Share\IShare $share |
||
| 416 | * @throws \Exception |
||
| 417 | */ |
||
| 418 | protected function groupCreateChecks(\OCP\Share\IShare $share) { |
||
| 419 | // Verify group shares are allowed |
||
| 420 | if (!$this->allowGroupSharing()) { |
||
| 421 | throw new \Exception('Group sharing is now allowed'); |
||
| 422 | } |
||
| 423 | |||
| 424 | // Verify if the user can share with this group |
||
| 425 | if ($this->shareWithGroupMembersOnly()) { |
||
| 426 | $sharedBy = $this->userManager->get($share->getSharedBy()); |
||
| 427 | $sharedWith = $this->groupManager->get($share->getSharedWith()); |
||
| 428 | if (is_null($sharedWith) || !$sharedWith->inGroup($sharedBy)) { |
||
| 429 | throw new \Exception('Only sharing within your own groups is allowed'); |
||
| 430 | } |
||
| 431 | } |
||
| 432 | |||
| 433 | /* |
||
| 434 | * TODO: Could be costly, fix |
||
| 435 | * |
||
| 436 | * Also this is not what we want in the future.. then we want to squash identical shares. |
||
| 437 | */ |
||
| 438 | $provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP); |
||
| 439 | $existingShares = $provider->getSharesByPath($share->getNode()); |
||
| 440 | foreach($existingShares as $existingShare) { |
||
| 441 | try { |
||
| 442 | if ($existingShare->getFullId() === $share->getFullId()) { |
||
| 443 | continue; |
||
| 444 | } |
||
| 445 | } catch (\UnexpectedValueException $e) { |
||
| 446 | //It is a new share so just continue |
||
| 447 | } |
||
| 448 | |||
| 449 | if ($existingShare->getSharedWith() === $share->getSharedWith()) { |
||
| 450 | throw new \Exception('Path already shared with this group'); |
||
| 451 | } |
||
| 452 | } |
||
| 453 | } |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Check for pre share requirements for link shares |
||
| 457 | * |
||
| 458 | * @param \OCP\Share\IShare $share |
||
| 459 | * @throws \Exception |
||
| 460 | */ |
||
| 461 | protected function linkCreateChecks(\OCP\Share\IShare $share) { |
||
| 462 | // Are link shares allowed? |
||
| 463 | if (!$this->shareApiAllowLinks()) { |
||
| 464 | throw new \Exception('Link sharing not allowed'); |
||
| 465 | } |
||
| 466 | |||
| 467 | // Link shares by definition can't have share permissions |
||
| 468 | if ($share->getPermissions() & \OCP\Constants::PERMISSION_SHARE) { |
||
| 469 | throw new \InvalidArgumentException('Link shares can\'t have reshare permissions'); |
||
| 470 | } |
||
| 471 | |||
| 472 | // Check if public upload is allowed |
||
| 473 | if (!$this->shareApiLinkAllowPublicUpload() && |
||
| 474 | ($share->getPermissions() & (\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE))) { |
||
| 475 | throw new \InvalidArgumentException('Public upload not allowed'); |
||
| 476 | } |
||
| 477 | } |
||
| 478 | |||
| 479 | /** |
||
| 480 | * To make sure we don't get invisible link shares we set the parent |
||
| 481 | * of a link if it is a reshare. This is a quick word around |
||
| 482 | * until we can properly display multiple link shares in the UI |
||
| 483 | * |
||
| 484 | * See: https://github.com/owncloud/core/issues/22295 |
||
| 485 | * |
||
| 486 | * FIXME: Remove once multiple link shares can be properly displayed |
||
| 487 | * |
||
| 488 | * @param \OCP\Share\IShare $share |
||
| 489 | */ |
||
| 490 | protected function setLinkParent(\OCP\Share\IShare $share) { |
||
| 491 | |||
| 492 | // No sense in checking if the method is not there. |
||
| 493 | if (method_exists($share, 'setParent')) { |
||
| 494 | $storage = $share->getNode()->getStorage(); |
||
| 495 | if ($storage->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { |
||
| 496 | /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
||
| 497 | $share->setParent($storage->getShareId()); |
||
| 498 | } |
||
| 499 | }; |
||
| 500 | } |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param File|Folder $path |
||
| 504 | */ |
||
| 505 | protected function pathCreateChecks($path) { |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Check if the user that is sharing can actually share |
||
| 519 | * |
||
| 520 | * @param \OCP\Share\IShare $share |
||
| 521 | * @throws \Exception |
||
| 522 | */ |
||
| 523 | protected function canShare(\OCP\Share\IShare $share) { |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Share a path |
||
| 535 | * |
||
| 536 | * @param \OCP\Share\IShare $share |
||
| 537 | * @return Share The share object |
||
| 538 | * @throws \Exception |
||
| 539 | * |
||
| 540 | * TODO: handle link share permissions or check them |
||
| 541 | */ |
||
| 542 | public function createShare(\OCP\Share\IShare $share) { |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Update a share |
||
| 670 | * |
||
| 671 | * @param \OCP\Share\IShare $share |
||
| 672 | * @return \OCP\Share\IShare The share object |
||
| 673 | * @throws \InvalidArgumentException |
||
| 674 | */ |
||
| 675 | public function updateShare(\OCP\Share\IShare $share) { |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Delete all the children of this share |
||
| 777 | * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
||
| 778 | * |
||
| 779 | * @param \OCP\Share\IShare $share |
||
| 780 | * @return \OCP\Share\IShare[] List of deleted shares |
||
| 781 | */ |
||
| 782 | protected function deleteChildren(\OCP\Share\IShare $share) { |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Delete a share |
||
| 800 | * |
||
| 801 | * @param \OCP\Share\IShare $share |
||
| 802 | * @throws ShareNotFound |
||
| 803 | * @throws \InvalidArgumentException |
||
| 804 | */ |
||
| 805 | public function deleteShare(\OCP\Share\IShare $share) { |
||
| 864 | |||
| 865 | |||
| 866 | /** |
||
| 867 | * Unshare a file as the recipient. |
||
| 868 | * This can be different from a regular delete for example when one of |
||
| 869 | * the users in a groups deletes that share. But the provider should |
||
| 870 | * handle this. |
||
| 871 | * |
||
| 872 | * @param \OCP\Share\IShare $share |
||
| 873 | * @param string $recipientId |
||
| 874 | */ |
||
| 875 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
||
| 881 | |||
| 882 | /** |
||
| 883 | * @inheritdoc |
||
| 884 | */ |
||
| 885 | public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
||
| 910 | |||
| 911 | public function getSharesInFolder($userId, Folder $node, $reshares = false) { |
||
| 926 | |||
| 927 | /** |
||
| 928 | * @inheritdoc |
||
| 929 | */ |
||
| 930 | public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
||
| 1000 | |||
| 1001 | /** |
||
| 1002 | * @inheritdoc |
||
| 1003 | */ |
||
| 1004 | public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * @inheritdoc |
||
| 1016 | */ |
||
| 1017 | public function getShareById($id, $recipient = null) { |
||
| 1042 | |||
| 1043 | /** |
||
| 1044 | * Get all the shares for a given path |
||
| 1045 | * |
||
| 1046 | * @param \OCP\Files\Node $path |
||
| 1047 | * @param int $page |
||
| 1048 | * @param int $perPage |
||
| 1049 | * |
||
| 1050 | * @return Share[] |
||
| 1051 | */ |
||
| 1052 | public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
||
| 1055 | |||
| 1056 | /** |
||
| 1057 | * Get the share by token possible with password |
||
| 1058 | * |
||
| 1059 | * @param string $token |
||
| 1060 | * @return Share |
||
| 1061 | * |
||
| 1062 | * @throws ShareNotFound |
||
| 1063 | */ |
||
| 1064 | public function getShareByToken($token) { |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Verify the password of a public share |
||
| 1119 | * |
||
| 1120 | * @param \OCP\Share\IShare $share |
||
| 1121 | * @param string $password |
||
| 1122 | * @return bool |
||
| 1123 | */ |
||
| 1124 | public function checkPassword(\OCP\Share\IShare $share, $password) { |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * @inheritdoc |
||
| 1150 | */ |
||
| 1151 | public function userDeleted($uid) { |
||
| 1163 | |||
| 1164 | /** |
||
| 1165 | * @inheritdoc |
||
| 1166 | */ |
||
| 1167 | public function groupDeleted($gid) { |
||
| 1171 | |||
| 1172 | /** |
||
| 1173 | * @inheritdoc |
||
| 1174 | */ |
||
| 1175 | public function userDeletedFromGroup($uid, $gid) { |
||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Get access list to a path. This means |
||
| 1182 | * all the users and groups that can access a given path. |
||
| 1183 | * |
||
| 1184 | * Consider: |
||
| 1185 | * -root |
||
| 1186 | * |-folder1 |
||
| 1187 | * |-folder2 |
||
| 1188 | * |-fileA |
||
| 1189 | * |
||
| 1190 | * fileA is shared with user1 |
||
| 1191 | * folder2 is shared with group2 |
||
| 1192 | * folder1 is shared with user2 |
||
| 1193 | * |
||
| 1194 | * Then the access list will to '/folder1/folder2/fileA' is: |
||
| 1195 | * [ |
||
| 1196 | * 'users' => ['user1', 'user2'], |
||
| 1197 | * 'groups' => ['group2'] |
||
| 1198 | * ] |
||
| 1199 | * |
||
| 1200 | * This is required for encryption |
||
| 1201 | * |
||
| 1202 | * @param \OCP\Files\Node $path |
||
| 1203 | */ |
||
| 1204 | public function getAccessList(\OCP\Files\Node $path) { |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Create a new share |
||
| 1209 | * @return \OCP\Share\IShare; |
||
| 1210 | */ |
||
| 1211 | public function newShare() { |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Is the share API enabled |
||
| 1217 | * |
||
| 1218 | * @return bool |
||
| 1219 | */ |
||
| 1220 | public function shareApiEnabled() { |
||
| 1223 | |||
| 1224 | /** |
||
| 1225 | * Is public link sharing enabled |
||
| 1226 | * |
||
| 1227 | * @return bool |
||
| 1228 | */ |
||
| 1229 | public function shareApiAllowLinks() { |
||
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Is password on public link requires |
||
| 1235 | * |
||
| 1236 | * @return bool |
||
| 1237 | */ |
||
| 1238 | public function shareApiLinkEnforcePassword() { |
||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * Is default expire date enabled |
||
| 1244 | * |
||
| 1245 | * @return bool |
||
| 1246 | */ |
||
| 1247 | public function shareApiLinkDefaultExpireDate() { |
||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Is default expire date enforced |
||
| 1253 | *` |
||
| 1254 | * @return bool |
||
| 1255 | */ |
||
| 1256 | public function shareApiLinkDefaultExpireDateEnforced() { |
||
| 1260 | |||
| 1261 | /** |
||
| 1262 | * Number of default expire days |
||
| 1263 | *shareApiLinkAllowPublicUpload |
||
| 1264 | * @return int |
||
| 1265 | */ |
||
| 1266 | public function shareApiLinkDefaultExpireDays() { |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Allow public upload on link shares |
||
| 1272 | * |
||
| 1273 | * @return bool |
||
| 1274 | */ |
||
| 1275 | public function shareApiLinkAllowPublicUpload() { |
||
| 1278 | |||
| 1279 | /** |
||
| 1280 | * check if user can only share with group members |
||
| 1281 | * @return bool |
||
| 1282 | */ |
||
| 1283 | public function shareWithGroupMembersOnly() { |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * Check if users can share with groups |
||
| 1289 | * @return bool |
||
| 1290 | */ |
||
| 1291 | public function allowGroupSharing() { |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Copied from \OC_Util::isSharingDisabledForUser |
||
| 1297 | * |
||
| 1298 | * TODO: Deprecate fuction from OC_Util |
||
| 1299 | * |
||
| 1300 | * @param string $userId |
||
| 1301 | * @return bool |
||
| 1302 | */ |
||
| 1303 | public function sharingDisabledForUser($userId) { |
||
| 1336 | |||
| 1337 | /** |
||
| 1338 | * @inheritdoc |
||
| 1339 | */ |
||
| 1340 | public function outgoingServer2ServerSharesAllowed() { |
||
| 1343 | |||
| 1344 | /** |
||
| 1345 | * @inheritdoc |
||
| 1346 | */ |
||
| 1347 | public function shareProviderExists($shareType) { |
||
| 1356 | |||
| 1357 | } |
||
| 1358 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: