Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing moderator overview on reshares #30884

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 36 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,12 +71,12 @@
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;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Log\LoggerInterface;

/**
* Class Share20OCS
Expand All @@ -95,6 +95,8 @@ class ShareAPIController extends OCSController {
private $rootFolder;
/** @var IURLGenerator */
private $urlGenerator;
/** @var LoggerInterface */
private $logger;
/** @var string */
private $currentUser;
/** @var IL10N */
Expand Down Expand Up @@ -122,6 +124,7 @@ class ShareAPIController extends OCSController {
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
* @param IURLGenerator $urlGenerator
* @param LoggerInterface $logger ,
* @param string $userId
* @param IL10N $l10n
* @param IConfig $config
Expand All @@ -137,6 +140,7 @@ public function __construct(
IUserManager $userManager,
IRootFolder $rootFolder,
IURLGenerator $urlGenerator,
LoggerInterface $logger,
string $userId = null,
IL10N $l10n,
IConfig $config,
Expand All @@ -153,6 +157,7 @@ public function __construct(
$this->request = $request;
$this->rootFolder = $rootFolder;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
$this->currentUser = $userId;
$this->l = $l10n;
$this->config = $config;
Expand Down Expand Up @@ -523,7 +528,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 +547,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 @@ -1742,7 +1747,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 @@ -1752,12 +1757,30 @@ 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) {
$this->logger->info(
'Exception while confirming resharing rights visibility',
[
'userId' => $userId,
'sharedWith' => $sharedWith,
'nodeId' => $node->getId(),
'exception' => $e,
]
);

return false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions apps/files_sharing/tests/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
use OCP\IServerContainer;
use OCP\Share\IShare;
use OCP\UserStatus\IManager as IUserStatusManager;
use Psr\Log\LoggerInterface;
use Psr\Log\Test\LoggerInterfaceTest;

/**
* Class ApiTest
Expand Down Expand Up @@ -128,6 +130,7 @@ private function createOCS($userId) {
\OC::$server->getUserManager(),
\OC::$server->getRootFolder(),
\OC::$server->getURLGenerator(),
$this->getMockBuilder(LoggerInterface::class)->getMock(),
$userId,
$l,
$config,
Expand Down
14 changes: 14 additions & 0 deletions apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\IManager;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Test\TestCase;
use OCP\UserStatus\IManager as IUserStatusManager;

Expand Down Expand Up @@ -92,6 +93,9 @@ class ShareAPIControllerTest extends TestCase {
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
private $urlGenerator;

/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $loggerInterface;

/** @var string|\PHPUnit\Framework\MockObject\MockObject */
private $currentUser;

Expand Down Expand Up @@ -130,6 +134,7 @@ protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->loggerInterface = $this->createMock(LoggerInterface::class);
$this->currentUser = 'currentUser';

$this->l = $this->createMock(IL10N::class);
Expand All @@ -155,6 +160,7 @@ protected function setUp(): void {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand All @@ -178,6 +184,7 @@ private function mockFormatShare() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -738,6 +745,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -1362,6 +1370,7 @@ public function testGetShares(array $getSharesParameters, array $shares, array $
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -1707,6 +1716,7 @@ public function testCreateShareUser() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -1809,6 +1819,7 @@ public function testCreateShareGroup() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -2190,6 +2201,7 @@ public function testCreateShareRemote() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -2260,6 +2272,7 @@ public function testCreateShareRemoteGroup() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down Expand Up @@ -2514,6 +2527,7 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() {
$this->userManager,
$this->rootFolder,
$this->urlGenerator,
$this->loggerInterface,
$this->currentUser,
$this->l,
$this->config,
Expand Down
8 changes: 5 additions & 3 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1534,11 +1534,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