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 3, 2022
1 parent e167d7f commit fa562f7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
49 changes: 29 additions & 20 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -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;
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,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;
}
}
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 fa562f7

Please sign in to comment.