Skip to content

Commit

Permalink
fixing moderator overview on reshares
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Feb 15, 2022
1 parent b3ba02b commit 8c84f51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
33 changes: 20 additions & 13 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(), ' '));
Expand All @@ -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;
}
}
Expand Down
8 changes: 5 additions & 3 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1557,11 +1557,13 @@
<RedundantCondition occurrences="1">
<code>$permissions &amp; Constants::PERMISSION_READ</code>
</RedundantCondition>
<UndefinedClass occurrences="2">
<code>\OCA\Circles\Api\v1\Circles</code>
<UndefinedClass occurrences="1">
<code>\OCA\Circles\Api\v1\Circles</code>
</UndefinedClass>
<UndefinedDocblockClass occurrences="4">
<UndefinedDocblockClass occurrences="7">
<code>$circleManager</code>
<code>$circleManager</code>
<code>$circleManager</code>
<code>$this-&gt;getRoomShareHelper()</code>
<code>$this-&gt;getRoomShareHelper()</code>
<code>$this-&gt;getRoomShareHelper()</code>
Expand Down

0 comments on commit 8c84f51

Please sign in to comment.