4444 */
4545namespace OCA \Files_Sharing \Controller ;
4646
47+ use OCA \Files \Helper ;
4748use OCA \Files_Sharing \Exceptions \SharingRightsException ;
4849use OCA \Files_Sharing \External \Storage ;
49- use OCA \Files \Helper ;
5050use OCP \App \IAppManager ;
5151use OCP \AppFramework \Http \DataResponse ;
5252use OCP \AppFramework \OCS \OCSBadRequestException ;
5656use OCP \AppFramework \OCSController ;
5757use OCP \AppFramework \QueryException ;
5858use OCP \Constants ;
59+ use OCP \Files \Folder ;
5960use OCP \Files \InvalidPathException ;
6061use OCP \Files \IRootFolder ;
61- use OCP \Files \Folder ;
6262use OCP \Files \Node ;
6363use OCP \Files \NotFoundException ;
6464use OCP \IConfig ;
7171use OCP \IUserManager ;
7272use OCP \Lock \ILockingProvider ;
7373use OCP \Lock \LockedException ;
74- use OCP \Share ;
7574use OCP \Share \Exceptions \GenericShareException ;
7675use OCP \Share \Exceptions \ShareNotFound ;
7776use OCP \Share \IManager ;
7877use OCP \Share \IShare ;
7978use OCP \UserStatus \IManager as IUserStatusManager ;
79+ use Psr \Log \LoggerInterface ;
8080
8181/**
8282 * Class Share20OCS
@@ -95,6 +95,8 @@ class ShareAPIController extends OCSController {
9595 private $ rootFolder ;
9696 /** @var IURLGenerator */
9797 private $ urlGenerator ;
98+ /** @var LoggerInterface */
99+ private $ logger ;
98100 /** @var string */
99101 private $ currentUser ;
100102 /** @var IL10N */
@@ -122,6 +124,7 @@ class ShareAPIController extends OCSController {
122124 * @param IUserManager $userManager
123125 * @param IRootFolder $rootFolder
124126 * @param IURLGenerator $urlGenerator
127+ * @param LoggerInterface $logger ,
125128 * @param string $userId
126129 * @param IL10N $l10n
127130 * @param IConfig $config
@@ -137,6 +140,7 @@ public function __construct(
137140 IUserManager $ userManager ,
138141 IRootFolder $ rootFolder ,
139142 IURLGenerator $ urlGenerator ,
143+ LoggerInterface $ logger ,
140144 string $ userId = null ,
141145 IL10N $ l10n ,
142146 IConfig $ config ,
@@ -153,6 +157,7 @@ public function __construct(
153157 $ this ->request = $ request ;
154158 $ this ->rootFolder = $ rootFolder ;
155159 $ this ->urlGenerator = $ urlGenerator ;
160+ $ this ->logger = $ logger ;
156161 $ this ->currentUser = $ userId ;
157162 $ this ->l = $ l10n ;
158163 $ this ->config = $ config ;
@@ -523,7 +528,7 @@ public function createShare(
523528 $ share ->setSharedWith ($ shareWith );
524529 $ share ->setPermissions ($ permissions );
525530 } elseif ($ shareType === IShare::TYPE_LINK
526- || $ shareType === IShare::TYPE_EMAIL ) {
531+ || $ shareType === IShare::TYPE_EMAIL ) {
527532
528533 // Can we even share links?
529534 if (!$ this ->shareManager ->shareApiAllowLinks ()) {
@@ -542,9 +547,9 @@ public function createShare(
542547 }
543548
544549 $ permissions = Constants::PERMISSION_READ |
545- Constants::PERMISSION_CREATE |
546- Constants::PERMISSION_UPDATE |
547- Constants::PERMISSION_DELETE ;
550+ Constants::PERMISSION_CREATE |
551+ Constants::PERMISSION_UPDATE |
552+ Constants::PERMISSION_DELETE ;
548553 } else {
549554 $ permissions = Constants::PERMISSION_READ ;
550555 }
@@ -1742,7 +1747,7 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no
17421747 }
17431748
17441749 if ($ share ->getShareType () === IShare::TYPE_CIRCLE && \OC ::$ server ->getAppManager ()->isEnabledForUser ('circles ' )
1745- && class_exists ('\OCA\Circles\Api\v1\Circles ' )) {
1750+ && class_exists ('\OCA\Circles\CirclesManager ' )) {
17461751 $ hasCircleId = (substr ($ share ->getSharedWith (), -1 ) === '] ' );
17471752 $ shareWithStart = ($ hasCircleId ? strrpos ($ share ->getSharedWith (), '[ ' ) + 1 : 0 );
17481753 $ shareWithLength = ($ hasCircleId ? -1 : strpos ($ share ->getSharedWith (), ' ' ));
@@ -1752,12 +1757,30 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no
17521757 $ sharedWith = substr ($ share ->getSharedWith (), $ shareWithStart , $ shareWithLength );
17531758 }
17541759 try {
1755- $ member = \OCA \Circles \Api \v1 \Circles::getMember ($ sharedWith , $ userId , 1 );
1756- if ($ member ->getLevel () >= 4 ) {
1757- return true ;
1760+ // TODO: switch to ICirclesManager once we have it available within core
1761+ /** @var \OCA\Circles\CirclesManager $circleManager */
1762+ $ circleManager = $ this ->serverContainer ->get ('\OCA\Circles\CirclesManager ' );
1763+ $ circleManager ->startSuperSession ();
1764+
1765+ // We get the federatedUser linked to the userId (local user, so type=1)
1766+ // We browse the federatedUser's membership to confirm it exists and level is moderator
1767+ $ federatedUser = $ circleManager ->getFederatedUser ($ userId , 1 );
1768+ foreach ($ federatedUser ->getMemberships () as $ membership ) {
1769+ if ($ membership ->getCircleId () === $ sharedWith ) {
1770+ return ($ membership ->getLevel () >= 4 );
1771+ }
17581772 }
1759- return false ;
1760- } catch (QueryException $ e ) {
1773+ } catch (\Exception $ e ) {
1774+ $ this ->logger ->info (
1775+ 'Exception while confirming resharing rights visibility ' ,
1776+ [
1777+ 'userId ' => $ userId ,
1778+ 'sharedWith ' => $ sharedWith ,
1779+ 'nodeId ' => $ node ->getId (),
1780+ 'exception ' => $ e ,
1781+ ]
1782+ );
1783+
17611784 return false ;
17621785 }
17631786 }
0 commit comments