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 |
||
57 | class Manager implements IManager { |
||
58 | |||
59 | /** @var IProviderFactory */ |
||
60 | private $factory; |
||
61 | /** @var ILogger */ |
||
62 | private $logger; |
||
63 | /** @var IConfig */ |
||
64 | private $config; |
||
65 | /** @var ISecureRandom */ |
||
66 | private $secureRandom; |
||
67 | /** @var IHasher */ |
||
68 | private $hasher; |
||
69 | /** @var IMountManager */ |
||
70 | private $mountManager; |
||
71 | /** @var IGroupManager */ |
||
72 | private $groupManager; |
||
73 | /** @var IL10N */ |
||
74 | private $l; |
||
75 | /** @var IUserManager */ |
||
76 | private $userManager; |
||
77 | /** @var IRootFolder */ |
||
78 | private $rootFolder; |
||
79 | /** @var CappedMemoryCache */ |
||
80 | private $sharingDisabledForUsersCache; |
||
81 | /** @var EventDispatcher */ |
||
82 | private $eventDispatcher; |
||
83 | |||
84 | /** @var View */ |
||
85 | private $view; |
||
86 | /** @var IDBConnection */ |
||
87 | private $connection; |
||
88 | |||
89 | /** |
||
90 | * Manager constructor. |
||
91 | * |
||
92 | * @param ILogger $logger |
||
93 | * @param IConfig $config |
||
94 | * @param ISecureRandom $secureRandom |
||
95 | * @param IHasher $hasher |
||
96 | * @param IMountManager $mountManager |
||
97 | * @param IGroupManager $groupManager |
||
98 | * @param IL10N $l |
||
99 | * @param IProviderFactory $factory |
||
100 | * @param IUserManager $userManager |
||
101 | * @param IRootFolder $rootFolder |
||
102 | */ |
||
103 | public function __construct( |
||
133 | |||
134 | /** |
||
135 | * @param int[] $shareTypes - ref \OC\Share\Constants[] |
||
136 | * @return int[] $providerIdMap e.g. { "ocinternal" => { 0, 1 }[2] }[1] |
||
137 | */ |
||
138 | private function shareTypeToProviderMap($shareTypes) { |
||
150 | |||
151 | /** |
||
152 | * Convert from a full share id to a tuple (providerId, shareId) |
||
153 | * |
||
154 | * @param string $id |
||
155 | * @return string[] |
||
156 | */ |
||
157 | private function splitFullId($id) { |
||
160 | |||
161 | /** |
||
162 | * Verify if a password meets all requirements |
||
163 | * |
||
164 | * @param string $password |
||
165 | * @throws \Exception |
||
166 | */ |
||
167 | protected function verifyPassword($password) { |
||
186 | |||
187 | /** |
||
188 | * Check if a password must be enforced if the shared has those permissions |
||
189 | * @param int $permissions \OCP\Constants::PERMISSION_* ("|" can be use for sets of permissions) |
||
190 | * @return bool true if the password must be enforced, false otherwise |
||
191 | */ |
||
192 | protected function passwordMustBeEnforced($permissions) { |
||
203 | |||
204 | /** |
||
205 | * Check for generic requirements before creating a share |
||
206 | * |
||
207 | * @param \OCP\Share\IShare $share |
||
208 | * @throws \InvalidArgumentException |
||
209 | * @throws GenericShareException |
||
210 | */ |
||
211 | protected function generalCreateChecks(\OCP\Share\IShare $share) { |
||
306 | |||
307 | /** |
||
308 | * Validate if the expiration date fits the system settings |
||
309 | * |
||
310 | * @param \OCP\Share\IShare $share The share to validate the expiration date of |
||
311 | * @return \OCP\Share\IShare The modified share object |
||
312 | * @throws GenericShareException |
||
313 | * @throws \InvalidArgumentException |
||
314 | * @throws \Exception |
||
315 | */ |
||
316 | protected function validateExpirationDate(\OCP\Share\IShare $share) { |
||
377 | |||
378 | /** |
||
379 | * Check for pre share requirements for user shares |
||
380 | * |
||
381 | * @param \OCP\Share\IShare $share |
||
382 | * @throws \Exception |
||
383 | */ |
||
384 | protected function userCreateChecks(\OCP\Share\IShare $share) { |
||
434 | |||
435 | /** |
||
436 | * Check for pre share requirements for group shares |
||
437 | * |
||
438 | * @param \OCP\Share\IShare $share |
||
439 | * @throws \Exception |
||
440 | */ |
||
441 | protected function groupCreateChecks(\OCP\Share\IShare $share) { |
||
477 | |||
478 | /** |
||
479 | * Check for pre share requirements for link shares |
||
480 | * |
||
481 | * @param \OCP\Share\IShare $share |
||
482 | * @throws \Exception |
||
483 | */ |
||
484 | protected function linkCreateChecks(\OCP\Share\IShare $share) { |
||
501 | |||
502 | /** |
||
503 | * To make sure we don't get invisible link shares we set the parent |
||
504 | * of a link if it is a reshare. This is a quick word around |
||
505 | * until we can properly display multiple link shares in the UI |
||
506 | * |
||
507 | * See: https://github.com/owncloud/core/issues/22295 |
||
508 | * |
||
509 | * FIXME: Remove once multiple link shares can be properly displayed |
||
510 | * |
||
511 | * @param \OCP\Share\IShare $share |
||
512 | */ |
||
513 | protected function setLinkParent(\OCP\Share\IShare $share) { |
||
523 | |||
524 | /** |
||
525 | * @param File|Folder $path |
||
526 | */ |
||
527 | protected function pathCreateChecks($path) { |
||
538 | |||
539 | /** |
||
540 | * Check if the user that is sharing can actually share |
||
541 | * |
||
542 | * @param \OCP\Share\IShare $share |
||
543 | * @throws \Exception |
||
544 | */ |
||
545 | protected function canShare(\OCP\Share\IShare $share) { |
||
554 | |||
555 | /** |
||
556 | * Share a path |
||
557 | * |
||
558 | * @param \OCP\Share\IShare $share |
||
559 | * @return Share The share object |
||
560 | * @throws \Exception |
||
561 | * |
||
562 | * TODO: handle link share permissions or check them |
||
563 | */ |
||
564 | public function createShare(\OCP\Share\IShare $share) { |
||
565 | $this->canShare($share); |
||
566 | |||
567 | $this->generalCreateChecks($share); |
||
568 | |||
569 | // Verify if there are any issues with the path |
||
570 | $this->pathCreateChecks($share->getNode()); |
||
571 | |||
572 | /* |
||
573 | * On creation of a share the owner is always the owner of the path |
||
574 | * Except for mounted federated shares. |
||
575 | */ |
||
576 | $storage = $share->getNode()->getStorage(); |
||
577 | if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
||
578 | $parent = $share->getNode()->getParent(); |
||
579 | while ($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) { |
||
580 | $parent = $parent->getParent(); |
||
581 | } |
||
582 | $share->setShareOwner($parent->getOwner()->getUID()); |
||
583 | } else { |
||
584 | $share->setShareOwner($share->getNode()->getOwner()->getUID()); |
||
585 | } |
||
586 | |||
587 | //Verify share type |
||
588 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
||
589 | $this->userCreateChecks($share); |
||
590 | } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
||
591 | $this->groupCreateChecks($share); |
||
592 | } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
||
593 | $this->linkCreateChecks($share); |
||
594 | $this->setLinkParent($share); |
||
595 | |||
596 | /* |
||
597 | * For now ignore a set token. |
||
598 | */ |
||
599 | $share->setToken( |
||
600 | $this->secureRandom->generate( |
||
601 | \OC\Share\Constants::TOKEN_LENGTH, |
||
602 | \OCP\Security\ISecureRandom::CHAR_LOWER. |
||
603 | \OCP\Security\ISecureRandom::CHAR_UPPER. |
||
604 | \OCP\Security\ISecureRandom::CHAR_DIGITS |
||
605 | ) |
||
606 | ); |
||
607 | |||
608 | //Verify the expiration date |
||
609 | $this->validateExpirationDate($share); |
||
610 | |||
611 | //Verify the password |
||
612 | if ($this->passwordMustBeEnforced($share->getPermissions()) && $share->getPassword() === null) { |
||
613 | throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
||
614 | } else { |
||
615 | $this->verifyPassword($share->getPassword()); |
||
616 | } |
||
617 | |||
618 | // If a password is set. Hash it! |
||
619 | if (($share->getPassword() !== null) && ($share->getShouldHashPassword() === true)) { |
||
620 | $share->setPassword($this->hasher->hash($share->getPassword())); |
||
621 | } |
||
622 | } |
||
623 | |||
624 | // Cannot share with the owner |
||
625 | View Code Duplication | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
626 | $share->getSharedWith() === $share->getShareOwner()) { |
||
627 | throw new \InvalidArgumentException('Can\'t share with the share owner'); |
||
628 | } |
||
629 | |||
630 | // Generate the target |
||
631 | $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName(); |
||
632 | $target = \OC\Files\Filesystem::normalizePath($target); |
||
633 | $share->setTarget($target); |
||
634 | |||
635 | // Pre share hook |
||
636 | $run = true; |
||
637 | $error = ''; |
||
638 | $preHookData = [ |
||
639 | 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
||
640 | 'itemSource' => $share->getNode()->getId(), |
||
641 | 'shareType' => $share->getShareType(), |
||
642 | 'uidOwner' => $share->getSharedBy(), |
||
643 | 'permissions' => $share->getPermissions(), |
||
644 | 'fileSource' => $share->getNode()->getId(), |
||
645 | 'expiration' => $share->getExpirationDate(), |
||
646 | 'token' => $share->getToken(), |
||
647 | 'itemTarget' => $share->getTarget(), |
||
648 | 'shareWith' => $share->getSharedWith(), |
||
649 | 'run' => &$run, |
||
650 | 'error' => &$error, |
||
651 | ]; |
||
652 | \OC_Hook::emit('OCP\Share', 'pre_shared', $preHookData); |
||
653 | |||
654 | $beforeEvent = new GenericEvent(null, ['shareData' => $preHookData, 'shareObject' => $share]); |
||
655 | $this->eventDispatcher->dispatch('share.beforeCreate', $beforeEvent); |
||
656 | |||
657 | if ($run === false) { |
||
658 | throw new \Exception($error); |
||
659 | } |
||
660 | |||
661 | $provider = $this->factory->getProviderForType($share->getShareType()); |
||
662 | $share = $provider->create($share); |
||
663 | |||
664 | // Post share hook |
||
665 | $postHookData = [ |
||
666 | 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
||
667 | 'itemSource' => $share->getNode()->getId(), |
||
668 | 'shareType' => $share->getShareType(), |
||
669 | 'uidOwner' => $share->getSharedBy(), |
||
670 | 'permissions' => $share->getPermissions(), |
||
671 | 'fileSource' => $share->getNode()->getId(), |
||
672 | 'expiration' => $share->getExpirationDate(), |
||
673 | 'token' => $share->getToken(), |
||
674 | 'id' => $share->getId(), |
||
675 | 'shareWith' => $share->getSharedWith(), |
||
676 | 'itemTarget' => $share->getTarget(), |
||
677 | 'fileTarget' => $share->getTarget(), |
||
678 | 'passwordEnabled' => ($share->getPassword() !== null and ($share->getPassword() !== '')), |
||
679 | ]; |
||
680 | |||
681 | \OC_Hook::emit('OCP\Share', 'post_shared', $postHookData); |
||
682 | |||
683 | $afterEvent = new GenericEvent(null, ['shareData' => $postHookData, 'shareObject' => $share]); |
||
684 | $this->eventDispatcher->dispatch('share.afterCreate', $afterEvent); |
||
685 | |||
686 | return $share; |
||
687 | } |
||
688 | |||
689 | /** |
||
690 | * Transfer shares from oldOwner to newOwner. Both old and new owners are uid |
||
691 | * |
||
692 | * finalTarget is of the form "user1/files/transferred from admin on 20180509" |
||
693 | * |
||
694 | * TransferShareException would be thrown when: |
||
695 | * - oldOwner, newOwner does not exist. |
||
696 | * - oldOwner and newOwner are same |
||
697 | * NotFoundException would be thrown when finalTarget does not exist in the file |
||
698 | * system |
||
699 | * |
||
700 | * @param IShare $share |
||
701 | * @param string $oldOwner |
||
702 | * @param string $newOwner |
||
703 | * @param string $finalTarget |
||
704 | * @param null|bool $isChild |
||
705 | * @throws TransferSharesException |
||
706 | * @throws NotFoundException |
||
707 | */ |
||
708 | public function transferShare(IShare $share, $oldOwner, $newOwner, $finalTarget, $isChild = null) { |
||
790 | |||
791 | /** |
||
792 | * Update a share |
||
793 | * |
||
794 | * @param \OCP\Share\IShare $share |
||
795 | * @return \OCP\Share\IShare The share object |
||
796 | * @throws \InvalidArgumentException |
||
797 | */ |
||
798 | public function updateShare(\OCP\Share\IShare $share) { |
||
799 | $expirationDateUpdated = false; |
||
800 | |||
801 | $this->canShare($share); |
||
802 | |||
803 | try { |
||
804 | $originalShare = $this->getShareById($share->getFullId()); |
||
805 | } catch (\UnexpectedValueException $e) { |
||
806 | throw new \InvalidArgumentException('Share does not have a full id'); |
||
807 | } |
||
808 | |||
809 | // We can't change the share type! |
||
810 | if ($share->getShareType() !== $originalShare->getShareType()) { |
||
811 | throw new \InvalidArgumentException('Can\'t change share type'); |
||
812 | } |
||
813 | |||
814 | // We can only change the recipient on user shares |
||
815 | if ($share->getSharedWith() !== $originalShare->getSharedWith() && |
||
816 | $share->getShareType() !== \OCP\Share::SHARE_TYPE_USER) { |
||
817 | throw new \InvalidArgumentException('Can only update recipient on user shares'); |
||
818 | } |
||
819 | |||
820 | // Cannot share with the owner |
||
821 | View Code Duplication | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && |
|
822 | $share->getSharedWith() === $share->getShareOwner()) { |
||
823 | throw new \InvalidArgumentException('Can\'t share with the share owner'); |
||
824 | } |
||
825 | |||
826 | $this->generalCreateChecks($share); |
||
827 | |||
828 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
||
829 | $this->userCreateChecks($share); |
||
830 | } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
||
831 | $this->groupCreateChecks($share); |
||
832 | } elseif ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
||
833 | $this->linkCreateChecks($share); |
||
834 | |||
835 | // Password updated. |
||
836 | if ($share->getPassword() !== $originalShare->getPassword() || |
||
837 | $share->getPermissions() !== $originalShare->getPermissions()) { |
||
838 | //Verify the password. Permissions must be taken into account in case the password must be enforced |
||
839 | if ($this->passwordMustBeEnforced($share->getPermissions()) && $share->getPassword() === null) { |
||
840 | throw new \InvalidArgumentException('Passwords are enforced for link shares'); |
||
841 | } else { |
||
842 | $this->verifyPassword($share->getPassword()); |
||
843 | } |
||
844 | |||
845 | // If a password is set. Hash it! (only if the password has changed) |
||
846 | if (($share->getPassword() !== null) && |
||
847 | ($share->getPassword() !== $originalShare->getPassword()) && |
||
848 | ($share->getShouldHashPassword() === true)) { |
||
849 | $share->setPassword($this->hasher->hash($share->getPassword())); |
||
850 | } |
||
851 | } |
||
852 | |||
853 | //Verify the expiration date |
||
854 | $this->validateExpirationDate($share); |
||
855 | |||
856 | if ($share->getExpirationDate() != $originalShare->getExpirationDate()) { |
||
857 | $expirationDateUpdated = true; |
||
858 | } |
||
859 | } |
||
860 | |||
861 | $this->pathCreateChecks($share->getNode()); |
||
862 | |||
863 | // Now update the share! |
||
864 | $provider = $this->factory->getProviderForType($share->getShareType()); |
||
865 | $share = $provider->update($share); |
||
866 | |||
867 | $shareAfterUpdateEvent = new GenericEvent(null); |
||
868 | $shareAfterUpdateEvent->setArgument('shareobject', $share); |
||
869 | $update = false; |
||
870 | View Code Duplication | if ($expirationDateUpdated === true) { |
|
871 | \OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [ |
||
872 | 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
||
873 | 'itemSource' => $share->getNode()->getId(), |
||
874 | 'date' => $share->getExpirationDate(), |
||
875 | 'uidOwner' => $share->getSharedBy(), |
||
876 | ]); |
||
877 | $shareAfterUpdateEvent->setArgument('expirationdateupdated', true); |
||
878 | $shareAfterUpdateEvent->setArgument('oldexpirationdate', $originalShare->getExpirationDate()); |
||
879 | $update = true; |
||
880 | } |
||
881 | |||
882 | View Code Duplication | if ($share->getPassword() !== $originalShare->getPassword()) { |
|
883 | \OC_Hook::emit('OCP\Share', 'post_update_password', [ |
||
884 | 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
||
885 | 'itemSource' => $share->getNode()->getId(), |
||
886 | 'uidOwner' => $share->getSharedBy(), |
||
887 | 'token' => $share->getToken(), |
||
888 | 'disabled' => $share->getPassword() === null, |
||
889 | ]); |
||
890 | $shareAfterUpdateEvent->setArgument('passwordupdate', true); |
||
891 | $update = true; |
||
892 | } |
||
893 | |||
894 | if ($share->getPermissions() !== $originalShare->getPermissions()) { |
||
895 | if ($this->userManager->userExists($share->getShareOwner())) { |
||
896 | $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); |
||
897 | } else { |
||
898 | $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); |
||
899 | } |
||
900 | \OC_Hook::emit('OCP\Share', 'post_update_permissions', [ |
||
901 | 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder', |
||
902 | 'itemSource' => $share->getNode()->getId(), |
||
903 | 'shareType' => $share->getShareType(), |
||
904 | 'shareWith' => $share->getSharedWith(), |
||
905 | 'uidOwner' => $share->getSharedBy(), |
||
906 | 'permissions' => $share->getPermissions(), |
||
907 | 'path' => $userFolder->getRelativePath($share->getNode()->getPath()), |
||
908 | ]); |
||
909 | $shareAfterUpdateEvent->setArgument('permissionupdate', true); |
||
910 | $shareAfterUpdateEvent->setArgument('oldpermissions', $originalShare->getPermissions()); |
||
911 | $shareAfterUpdateEvent->setArgument('path', $userFolder->getRelativePath($share->getNode()->getPath())); |
||
912 | $update = true; |
||
913 | } |
||
914 | |||
915 | if ($share->getName() !== $originalShare->getName()) { |
||
916 | $shareAfterUpdateEvent->setArgument('sharenameupdated', true); |
||
917 | $shareAfterUpdateEvent->setArgument('oldname', $originalShare->getName()); |
||
918 | $update = true; |
||
919 | } |
||
920 | |||
921 | if ($update === true) { |
||
922 | $this->eventDispatcher->dispatch('share.afterupdate', $shareAfterUpdateEvent); |
||
923 | } |
||
924 | return $share; |
||
925 | } |
||
926 | |||
927 | /** |
||
928 | * Delete all the children of this share |
||
929 | * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
||
930 | * |
||
931 | * @param \OCP\Share\IShare $share |
||
932 | * @return \OCP\Share\IShare[] List of deleted shares |
||
933 | */ |
||
934 | protected function deleteChildren(\OCP\Share\IShare $share) { |
||
949 | |||
950 | protected static function formatUnshareHookParams(\OCP\Share\IShare $share) { |
||
975 | |||
976 | /** |
||
977 | * Delete a share |
||
978 | * |
||
979 | * @param \OCP\Share\IShare $share |
||
980 | * @throws ShareNotFound |
||
981 | * @throws \InvalidArgumentException |
||
982 | */ |
||
983 | public function deleteShare(\OCP\Share\IShare $share) { |
||
1017 | |||
1018 | /** |
||
1019 | * Unshare a file as the recipient. |
||
1020 | * This can be different from a regular delete for example when one of |
||
1021 | * the users in a groups deletes that share. But the provider should |
||
1022 | * handle this. |
||
1023 | * |
||
1024 | * @param \OCP\Share\IShare $share |
||
1025 | * @param string $recipientId |
||
1026 | */ |
||
1027 | public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) { |
||
1049 | |||
1050 | /** |
||
1051 | * @inheritdoc |
||
1052 | */ |
||
1053 | public function moveShare(\OCP\Share\IShare $share, $recipientId) { |
||
1056 | |||
1057 | /** |
||
1058 | * @inheritdoc |
||
1059 | */ |
||
1060 | public function updateShareForRecipient(\OCP\Share\IShare $share, $recipientId) { |
||
1066 | |||
1067 | /** |
||
1068 | * @inheritdoc |
||
1069 | */ |
||
1070 | public function getAllSharesBy($userId, $shareTypes, $nodeIDs, $reshares = false) { |
||
1103 | |||
1104 | /** |
||
1105 | * @inheritdoc |
||
1106 | */ |
||
1107 | public function getSharesBy($userId, $shareType, $path = null, $reshares = false, $limit = 50, $offset = 0) { |
||
1173 | |||
1174 | /** |
||
1175 | * @inheritdoc |
||
1176 | */ |
||
1177 | public function getSharedWith($userId, $shareType, $node = null, $limit = 50, $offset = 0) { |
||
1182 | |||
1183 | /** |
||
1184 | * @inheritdoc |
||
1185 | */ |
||
1186 | public function getAllSharedWith($userId, $shareTypes, $node = null) { |
||
1202 | |||
1203 | /** |
||
1204 | * @inheritdoc |
||
1205 | */ |
||
1206 | public function getShareById($id, $recipient = null) { |
||
1226 | |||
1227 | /** |
||
1228 | * Get all the shares for a given path |
||
1229 | * |
||
1230 | * @param \OCP\Files\Node $path |
||
1231 | * @param int $page |
||
1232 | * @param int $perPage |
||
1233 | * |
||
1234 | * @return Share[] |
||
1235 | */ |
||
1236 | public function getSharesByPath(\OCP\Files\Node $path, $page=0, $perPage=50) { |
||
1253 | |||
1254 | /** |
||
1255 | * Get the share by token possible with password |
||
1256 | * |
||
1257 | * @param string $token |
||
1258 | * @return Share |
||
1259 | * |
||
1260 | * @throws ShareNotFound |
||
1261 | */ |
||
1262 | public function getShareByToken($token) { |
||
1293 | |||
1294 | /** |
||
1295 | * Verify the password of a public share |
||
1296 | * |
||
1297 | * @param \OCP\Share\IShare $share |
||
1298 | * @param string $password |
||
1299 | * @return bool |
||
1300 | */ |
||
1301 | public function checkPassword(\OCP\Share\IShare $share, $password) { |
||
1324 | |||
1325 | /** |
||
1326 | * @inheritdoc |
||
1327 | */ |
||
1328 | public function userDeleted($uid) { |
||
1336 | |||
1337 | /** |
||
1338 | * @inheritdoc |
||
1339 | */ |
||
1340 | public function groupDeleted($gid) { |
||
1344 | |||
1345 | /** |
||
1346 | * @inheritdoc |
||
1347 | */ |
||
1348 | public function userDeletedFromGroup($uid, $gid) { |
||
1352 | |||
1353 | /** |
||
1354 | * Get access list to a path. This means |
||
1355 | * all the users and groups that can access a given path. |
||
1356 | * |
||
1357 | * Consider: |
||
1358 | * -root |
||
1359 | * |-folder1 |
||
1360 | * |-folder2 |
||
1361 | * |-fileA |
||
1362 | * |
||
1363 | * fileA is shared with user1 |
||
1364 | * folder2 is shared with group2 |
||
1365 | * folder1 is shared with user2 |
||
1366 | * |
||
1367 | * Then the access list will to '/folder1/folder2/fileA' is: |
||
1368 | * [ |
||
1369 | * 'users' => ['user1', 'user2'], |
||
1370 | * 'groups' => ['group2'] |
||
1371 | * ] |
||
1372 | * |
||
1373 | * This is required for encryption |
||
1374 | * |
||
1375 | * @param \OCP\Files\Node $path |
||
1376 | */ |
||
1377 | public function getAccessList(\OCP\Files\Node $path) { |
||
1379 | |||
1380 | /** |
||
1381 | * Create a new share |
||
1382 | * @return \OCP\Share\IShare; |
||
1383 | */ |
||
1384 | public function newShare() { |
||
1387 | |||
1388 | /** |
||
1389 | * Is the share API enabled |
||
1390 | * |
||
1391 | * @return bool |
||
1392 | */ |
||
1393 | public function shareApiEnabled() { |
||
1396 | |||
1397 | /** |
||
1398 | * Is public link sharing enabled |
||
1399 | * |
||
1400 | * @return bool |
||
1401 | */ |
||
1402 | public function shareApiAllowLinks() { |
||
1405 | |||
1406 | /** |
||
1407 | * Is password on public link requires (fallback to shareApiLinkEnforcePasswordReadOnly) |
||
1408 | * |
||
1409 | * @return bool |
||
1410 | */ |
||
1411 | public function shareApiLinkEnforcePassword() { |
||
1414 | |||
1415 | /** |
||
1416 | * Is password enforced for read-only shares? |
||
1417 | * |
||
1418 | * @return bool |
||
1419 | */ |
||
1420 | public function shareApiLinkEnforcePasswordReadOnly() { |
||
1423 | |||
1424 | /** |
||
1425 | * Is password enforced for read & write shares? |
||
1426 | * |
||
1427 | * @return bool |
||
1428 | */ |
||
1429 | public function shareApiLinkEnforcePasswordReadWrite() { |
||
1432 | |||
1433 | /** |
||
1434 | * Is password enforced for write-only shares? |
||
1435 | * |
||
1436 | * @return bool |
||
1437 | */ |
||
1438 | public function shareApiLinkEnforcePasswordWriteOnly() { |
||
1441 | |||
1442 | /** |
||
1443 | * Is default expire date enabled |
||
1444 | * |
||
1445 | * @return bool |
||
1446 | */ |
||
1447 | public function shareApiLinkDefaultExpireDate() { |
||
1450 | |||
1451 | /** |
||
1452 | * Is default expire date enforced |
||
1453 | *` |
||
1454 | * @return bool |
||
1455 | */ |
||
1456 | public function shareApiLinkDefaultExpireDateEnforced() { |
||
1460 | |||
1461 | /** |
||
1462 | * Number of default expire days |
||
1463 | *shareApiLinkAllowPublicUpload |
||
1464 | * @return int |
||
1465 | */ |
||
1466 | public function shareApiLinkDefaultExpireDays() { |
||
1469 | |||
1470 | /** |
||
1471 | * Allow public upload on link shares |
||
1472 | * |
||
1473 | * @return bool |
||
1474 | */ |
||
1475 | public function shareApiLinkAllowPublicUpload() { |
||
1478 | |||
1479 | /** |
||
1480 | * check if user can only share with group members |
||
1481 | * @return bool |
||
1482 | */ |
||
1483 | public function shareWithGroupMembersOnly() { |
||
1486 | |||
1487 | /** |
||
1488 | * check if user can only share with groups he's member of |
||
1489 | * @return bool |
||
1490 | */ |
||
1491 | public function shareWithMembershipGroupOnly() { |
||
1494 | |||
1495 | /** |
||
1496 | * Check if users can share with groups |
||
1497 | * @return bool |
||
1498 | */ |
||
1499 | public function allowGroupSharing() { |
||
1502 | |||
1503 | /** |
||
1504 | * Copied from \OC_Util::isSharingDisabledForUser |
||
1505 | * |
||
1506 | * @param string $userId |
||
1507 | * @return bool |
||
1508 | */ |
||
1509 | public function sharingDisabledForUser($userId) { |
||
1539 | |||
1540 | /** |
||
1541 | * @inheritdoc |
||
1542 | */ |
||
1543 | public function outgoingServer2ServerSharesAllowed() { |
||
1546 | } |
||
1547 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.