diff options
author | Joas Schilling <coding@schilljs.com> | 2019-07-03 16:32:45 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-07-03 16:34:00 +0200 |
commit | 85a80b05acbb6e13d8b49d1ee7f79e9a8c708066 (patch) | |
tree | e340955eb97afc58ebb6358d4d938ae736b0cf7d /apps/files_sharing/lib | |
parent | e4addbae3e564b6009dc09c6c5e36c018cd8d5d0 (diff) | |
download | nextcloud-server-85a80b05acbb6e13d8b49d1ee7f79e9a8c708066.tar.gz nextcloud-server-85a80b05acbb6e13d8b49d1ee7f79e9a8c708066.zip |
Unify the permission checking in one place only
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/files_sharing/lib')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 66e39bb0715..09489861e1c 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -971,41 +971,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); } |