summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-07-03 16:32:45 +0200
committerMorris Jobke <hey@morrisjobke.de>2019-07-03 21:31:40 +0200
commit132902337e7eee582034d4a1bc0552cd6e0cffb6 (patch)
tree77cb4a60674b2c5e36759e26dc39954a638832a8 /apps/files_sharing
parent029ecb7966a5b38ca98cf770fca88c243684f8ad (diff)
downloadnextcloud-server-132902337e7eee582034d4a1bc0552cd6e0cffb6.tar.gz
nextcloud-server-132902337e7eee582034d4a1bc0552cd6e0cffb6.zip
Unify the permission checking in one place only
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php33
-rw-r--r--apps/files_sharing/tests/Controller/ShareAPIControllerTest.php11
2 files changed, 11 insertions, 33 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 188c8637881..46216c7ebbe 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -951,40 +951,13 @@ class ShareAPIController extends OCSController {
}
$share->setExpirationDate($expireDate);
}
-
- }
-
- if ($permissions !== null && $share->getShareOwner() !== $this->currentUser) {
- // Get the root mount point for the user and check the share permissions there
- $userFolder = $this->rootFolder->getUserFolder($this->currentUser);
- $userNodes = $userFolder->getById($share->getNodeId());
- $userNode = array_shift($userNodes);
-
- $userMountPointId = $userNode->getMountPoint()->getStorageRootId();
- $userMountPoints = $userFolder->getById($userMountPointId);
- $userMountPoint = array_shift($userMountPoints);
-
- /* Check if this is an incoming share */
- $incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $userMountPoint, -1, 0);
- $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $userMountPoint, -1, 0));
- $incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $userMountPoint, -1, 0));
-
- /** @var \OCP\Share\IShare[] $incomingShares */
- if (!empty($incomingShares)) {
- $maxPermissions = 0;
- foreach ($incomingShares as $incomingShare) {
- $maxPermissions |= $incomingShare->getPermissions();
- }
-
- if ($share->getPermissions() & ~$maxPermissions) {
- throw new OCSNotFoundException($this->l->t('Cannot increase permissions'));
- }
- }
}
-
try {
$share = $this->shareManager->updateShare($share);
+ } catch (GenericShareException $e) {
+ $code = $e->getCode() === 0 ? 403 : $e->getCode();
+ throw new OCSException($e->getHint(), $code);
} catch (\Exception $e) {
throw new OCSBadRequestException($e->getMessage(), $e);
}
diff --git a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
index f00b5c424bf..80b47d85df6 100644
--- a/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareAPIControllerTest.php
@@ -28,6 +28,7 @@ namespace OCA\Files_Sharing\Tests\Controller;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
+use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\Files\File;
use OCP\Files\Folder;
@@ -45,6 +46,7 @@ use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Files\IRootFolder;
use OCP\Lock\LockedException;
+use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\IManager;
use OCP\Share;
use Test\TestCase;
@@ -2418,13 +2420,16 @@ class ShareAPIControllerTest extends TestCase {
$mountPoint->method('getStorageRootId')
->willReturn(42);
- $this->shareManager->expects($this->never())->method('updateShare');
+ $this->shareManager->expects($this->once())
+ ->method('updateShare')
+ ->with($share)
+ ->willThrowException(new GenericShareException('Can’t increase permissions of path/file', 'Can’t increase permissions of path/file', 404));
try {
$ocs->updateShare(42, 31);
$this->fail();
- } catch (OCSNotFoundException $e) {
- $this->assertEquals('Cannot increase permissions', $e->getMessage());
+ } catch (OCSException $e) {
+ $this->assertEquals('Can’t increase permissions of path/file', $e->getMessage());
}
}