Skip to content

Commit c1c502b

Browse files
authored
Merge pull request #34704 from nextcloud/backport/34502/stable25
[stable25] Propagate attributes when resharing
2 parents 4a448f3 + a318699 commit c1c502b

File tree

2 files changed

+106
-185
lines changed

2 files changed

+106
-185
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ public function createShare(
533533
$permissions &= ~($permissions & ~$node->getPermissions());
534534
}
535535

536+
if ($attributes !== null) {
537+
$share = $this->setShareAttributes($share, $attributes);
538+
}
539+
540+
$share->setSharedBy($this->currentUser);
536541
$this->checkInheritedAttributes($share);
537542

538543
if ($shareType === IShare::TYPE_USER) {
@@ -687,16 +692,11 @@ public function createShare(
687692
}
688693

689694
$share->setShareType($shareType);
690-
$share->setSharedBy($this->currentUser);
691695

692696
if ($note !== '') {
693697
$share->setNote($note);
694698
}
695699

696-
if ($attributes !== null) {
697-
$share = $this->setShareAttributes($share, $attributes);
698-
}
699-
700700
try {
701701
$share = $this->shareManager->createShare($share);
702702
} catch (GenericShareException $e) {
@@ -1112,24 +1112,10 @@ public function updateShare(
11121112
$share->setNote($note);
11131113
}
11141114

1115-
$userFolder = $this->rootFolder->getUserFolder($this->currentUser);
1116-
1117-
// get the node with the point of view of the current user
1118-
$nodes = $userFolder->getById($share->getNode()->getId());
1119-
if (count($nodes) > 0) {
1120-
$node = $nodes[0];
1121-
$storage = $node->getStorage();
1122-
if ($storage && $storage->instanceOfStorage(SharedStorage::class)) {
1123-
/** @var \OCA\Files_Sharing\SharedStorage $storage */
1124-
$inheritedAttributes = $storage->getShare()->getAttributes();
1125-
if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
1126-
if ($hideDownload === 'false') {
1127-
throw new OCSBadRequestException($this->l->t('Cannot increase permissions'));
1128-
}
1129-
$share->setHideDownload(true);
1130-
}
1131-
}
1115+
if ($attributes !== null) {
1116+
$share = $this->setShareAttributes($share, $attributes);
11321117
}
1118+
$this->checkInheritedAttributes($share);
11331119

11341120
/**
11351121
* expirationdate, password and publicUpload only make sense for link shares
@@ -1263,10 +1249,6 @@ public function updateShare(
12631249
}
12641250
}
12651251

1266-
if ($attributes !== null) {
1267-
$share = $this->setShareAttributes($share, $attributes);
1268-
}
1269-
12701252
try {
12711253
$share = $this->shareManager->updateShare($share);
12721254
} catch (GenericShareException $e) {
@@ -1912,8 +1894,17 @@ private function setShareAttributes(IShare $share, ?string $attributesString) {
19121894
}
19131895

19141896
private function checkInheritedAttributes(IShare $share): void {
1915-
if ($share->getNode()->getStorage()->instanceOfStorage(SharedStorage::class)) {
1916-
$storage = $share->getNode()->getStorage();
1897+
if (!$share->getSharedBy()) {
1898+
return; // Probably in a test
1899+
}
1900+
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
1901+
$nodes = $userFolder->getById($share->getNodeId());
1902+
if (empty($nodes)) {
1903+
return;
1904+
}
1905+
$node = $nodes[0];
1906+
if ($node->getStorage()->instanceOfStorage(SharedStorage::class)) {
1907+
$storage = $node->getStorage();
19171908
if ($storage instanceof Wrapper) {
19181909
$storage = $storage->getInstanceOfStorage(SharedStorage::class);
19191910
if ($storage === null) {
@@ -1926,6 +1917,11 @@ private function checkInheritedAttributes(IShare $share): void {
19261917
$inheritedAttributes = $storage->getShare()->getAttributes();
19271918
if ($inheritedAttributes !== null && $inheritedAttributes->getAttribute('permissions', 'download') === false) {
19281919
$share->setHideDownload(true);
1920+
$attributes = $share->getAttributes();
1921+
if ($attributes) {
1922+
$attributes->setAttribute('permissions', 'download', false);
1923+
$share->setAttributes($attributes);
1924+
}
19291925
}
19301926
}
19311927

0 commit comments

Comments
 (0)