From 42d957e6f837a04601b890ec3e23281950a78f1a Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 14 Nov 2022 16:00:58 +0100 Subject: [PATCH] Revert "Propagate attributes when resharing" This reverts https://github.com/nextcloud/server/pull/34840 for a test for https://github.com/nextcloud/server/issues/34976 Signed-off-by: Simon L --- .../lib/Controller/ShareAPIController.php | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 0bd7770880580..66b3153f09957 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -525,11 +525,6 @@ public function createShare( $permissions &= ~($permissions & ~$node->getPermissions()); } - if ($attributes !== null) { - $share = $this->setShareAttributes($share, $attributes); - } - - $share->setSharedBy($this->currentUser); $this->checkInheritedAttributes($share); if ($shareType === IShare::TYPE_USER) { @@ -684,11 +679,16 @@ public function createShare( } $share->setShareType($shareType); + $share->setSharedBy($this->currentUser); if ($note !== '') { $share->setNote($note); } + if ($attributes !== null) { + $share = $this->setShareAttributes($share, $attributes); + } + try { $share = $this->shareManager->createShare($share); } catch (GenericShareException $e) { @@ -1104,10 +1104,24 @@ public function updateShare( $share->setNote($note); } - if ($attributes !== null) { - $share = $this->setShareAttributes($share, $attributes); + $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); + } + } } - $this->checkInheritedAttributes($share); /** * expirationdate, password and publicUpload only make sense for link shares @@ -1239,6 +1253,10 @@ public function updateShare( } } + if ($attributes !== null) { + $share = $this->setShareAttributes($share, $attributes); + } + try { $share = $this->shareManager->updateShare($share); } catch (GenericShareException $e) { @@ -1884,17 +1902,8 @@ private function setShareAttributes(IShare $share, ?string $attributesString) { } private function checkInheritedAttributes(IShare $share): void { - if (!$share->getSharedBy()) { - return; // Probably in a test - } - $userFolder = $this->rootFolder->getUserFolder($share->getSharedBy()); - $nodes = $userFolder->getById($share->getNodeId()); - if (empty($nodes)) { - return; - } - $node = $nodes[0]; - if ($node->getStorage()->instanceOfStorage(SharedStorage::class)) { - $storage = $node->getStorage(); + if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) { + $storage = $share->getNode()->getStorage(); if ($storage instanceof Wrapper) { $storage = $storage->getInstanceOfStorage(SharedStorage::class); if ($storage === null) { @@ -1907,11 +1916,6 @@ private function checkInheritedAttributes(IShare $share): void { $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); - } } }