summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-10-10 16:09:14 +0200
committerCarl Schwan <carl@carlschwan.eu>2022-10-10 17:06:29 +0200
commitcf39885b539e15ee39f40486370ac7baafa90d82 (patch)
tree6623c2b370505941ee50eaddd54cd8403487596e /apps
parentcf5bf3036dee4527b93c5bb8e43c0ed3a216e15a (diff)
downloadnextcloud-server-cf39885b539e15ee39f40486370ac7baafa90d82.tar.gz
nextcloud-server-cf39885b539e15ee39f40486370ac7baafa90d82.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.php47
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 00f12ea7779..2689cdd79e7 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -533,6 +533,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) {
@@ -693,10 +697,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) {
@@ -1112,24 +1112,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
@@ -1263,10 +1249,6 @@ class ShareAPIController extends OCSController {
}
}
- if ($attributes !== null) {
- $share = $this->setShareAttributes($share, $attributes);
- }
-
try {
$share = $this->shareManager->updateShare($share);
} catch (GenericShareException $e) {
@@ -1912,8 +1894,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) {
@@ -1926,6 +1914,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);
+ }
}
}