diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-10-10 16:09:14 +0200 |
---|---|---|
committer | Vincent Petry <vincent@nextcloud.com> | 2022-10-27 10:48:48 +0200 |
commit | ff653f4d762b03bbb1c6ede5b450133748adac7a (patch) | |
tree | ac2dbc9b839348f43c5d6335dbf19513eab137cc /apps | |
parent | 637a58f18fd09579ed62818f6b1efd17b39fb244 (diff) | |
download | nextcloud-server-ff653f4d762b03bbb1c6ede5b450133748adac7a.tar.gz nextcloud-server-ff653f4d762b03bbb1c6ede5b450133748adac7a.zip |
Propagate attributes when resharing
When updating a share, load the node from the initiator instead of the
owner similar to how this is done when creating the share.
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareAPIController.php | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 66b3153f099..8ceb6318637 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -525,6 +525,10 @@ class ShareAPIController extends OCSController { $permissions &= ~($permissions & ~$node->getPermissions()); } + if ($attributes !== null) { + $share = $this->setShareAttributes($share, $attributes); + } + $this->checkInheritedAttributes($share); if ($shareType === IShare::TYPE_USER) { @@ -685,10 +689,6 @@ class ShareAPIController extends OCSController { $share->setNote($note); } - if ($attributes !== null) { - $share = $this->setShareAttributes($share, $attributes); - } - try { $share = $this->shareManager->createShare($share); } catch (GenericShareException $e) { @@ -1104,24 +1104,10 @@ class ShareAPIController extends OCSController { $share->setNote($note); } - $userFolder = $this->rootFolder->getUserFolder($this->currentUser); - - // get the node with the point of view of the current user - $nodes = $userFolder->getById($share->getNode()->getId()); - if (count($nodes) > 0) { - $node = $nodes[0]; - $storage = $node->getStorage(); - if ($storage && $storage->instanceOfStorage(SharedStorage::class)) { - /** @var \OCA\Files_Sharing\SharedStorage $storage */ - $inheritedAttributes = $storage->getShare()->getAttributes(); - if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) { - if ($hideDownload === 'false') { - throw new OCSBadRequestException($this->l->t('Cannot increase permissions')); - } - $share->setHideDownload(true); - } - } + if ($attributes !== null) { + $share = $this->setShareAttributes($share, $attributes); } + $this->checkInheritedAttributes($share); /** * expirationdate, password and publicUpload only make sense for link shares @@ -1253,10 +1239,6 @@ class ShareAPIController extends OCSController { } } - if ($attributes !== null) { - $share = $this->setShareAttributes($share, $attributes); - } - try { $share = $this->shareManager->updateShare($share); } catch (GenericShareException $e) { @@ -1902,8 +1884,14 @@ class ShareAPIController extends OCSController { } private function checkInheritedAttributes(IShare $share): void { - if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) { - $storage = $share->getNode()->getStorage(); + $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); + $nodes = $userFolder->getById($share->getNodeId()); + if (empty($nodes)) { + throw new NotFoundException('Node for share not found, fileid: ' . $share->getNodeId()); + } + $node = $nodes[0]; + if ($node->getStorage()->instanceOfStorage(SharedStorage::class)) { + $storage = $node->getStorage(); if ($storage instanceof Wrapper) { $storage = $storage->getInstanceOfStorage(SharedStorage::class); if ($storage === null) { @@ -1916,6 +1904,11 @@ class ShareAPIController extends OCSController { $inheritedAttributes = $storage->getShare()->getAttributes(); if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) { $share->setHideDownload(true); + $attributes = $share->getAttributes(); + if ($attributes) { + $attributes->setAttribute('permissions', 'download', false); + $share->setAttributes($attributes); + } } } |