From 0ecd1f86662e68bbcf334df545425b6031cbaec3 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Mon, 31 Jan 2022 15:20:12 -0100 Subject: [PATCH] fixing moderator overview on reshares Signed-off-by: Maxence Lange --- .../lib/Controller/ShareAPIController.php | 49 +++++++++++-------- build/psalm-baseline.xml | 8 +-- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index ff134f61e1739..c8e0f02b340ac 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -71,7 +71,6 @@ use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; -use OCP\Share; use OCP\Share\Exceptions\GenericShareException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; @@ -523,7 +522,7 @@ public function createShare( $share->setSharedWith($shareWith); $share->setPermissions($permissions); } elseif ($shareType === IShare::TYPE_LINK - || $shareType === IShare::TYPE_EMAIL) { + || $shareType === IShare::TYPE_EMAIL) { // Can we even share links? if (!$this->shareManager->shareApiAllowLinks()) { @@ -542,9 +541,9 @@ public function createShare( } $permissions = Constants::PERMISSION_READ | - Constants::PERMISSION_CREATE | - Constants::PERMISSION_UPDATE | - Constants::PERMISSION_DELETE; + Constants::PERMISSION_CREATE | + Constants::PERMISSION_UPDATE | + Constants::PERMISSION_DELETE; } else { $permissions = Constants::PERMISSION_READ; } @@ -1234,17 +1233,17 @@ public function pendingShares(): DataResponse { $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); $nodes = $userFolder->getById($share->getNodeId()); if (empty($nodes)) { - // fallback to guessing the path - $node = $userFolder->get($share->getTarget()); - if ($node === null || $share->getTarget() === '') { - return null; + // fallback to guessing the path + $node = $userFolder->get($share->getTarget()); + if ($node === null || $share->getTarget() === '') { + return null; + } + } else { + $node = $nodes[0]; } - } else { - $node = $nodes[0]; - } - try { - $formattedShare = $this->formatShare($share, $node); + try { + $formattedShare = $this->formatShare($share, $node); $formattedShare['status'] = $share->getStatus(); $formattedShare['path'] = $share->getNode()->getName(); $formattedShare['permissions'] = 0; @@ -1735,7 +1734,7 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no } if ($share->getShareType() === IShare::TYPE_CIRCLE && \OC::$server->getAppManager()->isEnabledForUser('circles') - && class_exists('\OCA\Circles\Api\v1\Circles')) { + && class_exists('\OCA\Circles\CirclesManager')) { $hasCircleId = (substr($share->getSharedWith(), -1) === ']'); $shareWithStart = ($hasCircleId ? strrpos($share->getSharedWith(), '[') + 1 : 0); $shareWithLength = ($hasCircleId ? -1 : strpos($share->getSharedWith(), ' ')); @@ -1745,12 +1744,22 @@ private function shareProviderResharingRights(string $userId, IShare $share, $no $sharedWith = substr($share->getSharedWith(), $shareWithStart, $shareWithLength); } try { - $member = \OCA\Circles\Api\v1\Circles::getMember($sharedWith, $userId, 1); - if ($member->getLevel() >= 4) { - return true; + // TODO: switch to ICirclesManager once we have it available within core + /** @var \OCA\Circles\CirclesManager $circleManager */ + $circleManager = $this->serverContainer->get('\OCA\Circles\CirclesManager'); + $circleManager->startSuperSession(); + + // We get the federatedUser linked to the userId (local user, so type=1) + // We browse the federatedUser's membership to confirm it exists and level is moderator + $federatedUser = $circleManager->getFederatedUser($userId, 1); + foreach($federatedUser->getMemberships() as $membership) { + if ($membership->getCircleId() !== $sharedWith) { + continue; + } + + return ($membership->getLevel() >= 4); } - return false; - } catch (QueryException $e) { + } catch (\Exception $e) { return false; } } diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 60768e781eaae..419b6cfd135ac 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1557,11 +1557,13 @@ $permissions & Constants::PERMISSION_READ - - \OCA\Circles\Api\v1\Circles + \OCA\Circles\Api\v1\Circles - + + $circleManager + $circleManager + $circleManager $this->getRoomShareHelper() $this->getRoomShareHelper() $this->getRoomShareHelper()