diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index ff134f61e1739..fe0b8bd90caf3 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -44,9 +44,9 @@ */ namespace OCA\Files_Sharing\Controller; +use OCA\Files\Helper; use OCA\Files_Sharing\Exceptions\SharingRightsException; use OCA\Files_Sharing\External\Storage; -use OCA\Files\Helper; use OCP\App\IAppManager; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSBadRequestException; @@ -56,9 +56,9 @@ use OCP\AppFramework\OCSController; use OCP\AppFramework\QueryException; use OCP\Constants; +use OCP\Files\Folder; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; -use OCP\Files\Folder; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IConfig; @@ -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; } @@ -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,20 @@ 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) { + 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 d5092282088fb..66d297e24ac0f 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()