Skip to content

Commit 8ed4c1a

Browse files
committed
fix(sharing): Allow reasonable control 4 'Hide download' on fed shares
When creating public links from federated shares, users should be able to set the 'Hide download' option independently as long as they are more restrictive than the original share permissions. Previously, the `checkInheritedAttributes` method was ignoring user preferences and always overriding the hideDownload setting based solely on inherited permissions, preventing users from disabling downloads even when the parent share allowed them. This fix implements some sort of inheritance logic: - Users can only be MORE restrictive than parent shares, never LESS restrictive - If parent hides downloads -> child MUST hide downloads (enforced) - If parent allows downloads -> child can CHOOSE to hide or allow downloads - If parent forbids downloads entirely -> child cannot enable downloads Signed-off-by: nfebe <fenn25.fn@gmail.com>
1 parent 8e5f436 commit 8ed4c1a

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,6 +2095,7 @@ private function checkInheritedAttributes(IShare $share): void {
20952095

20962096
$canDownload = false;
20972097
$hideDownload = true;
2098+
$userExplicitlySetHideDownload = $share->getHideDownload(); // Capture user's explicit choice
20982099

20992100
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
21002101
$nodes = $userFolder->getById($share->getNodeId());
@@ -2120,23 +2121,44 @@ private function checkInheritedAttributes(IShare $share): void {
21202121
/** @var SharedStorage $storage */
21212122
$originalShare = $storage->getShare();
21222123
$inheritedAttributes = $originalShare->getAttributes();
2123-
// hide if hidden and also the current share enforces hide (can only be false if one share is false or user is owner)
2124-
$hideDownload = $hideDownload && $originalShare->getHideDownload();
2125-
// allow download if already allowed by previous share or when the current share allows downloading
2126-
$canDownload = $canDownload || $inheritedAttributes === null || $inheritedAttributes->getAttribute('permissions', 'download') !== false;
2124+
2125+
// For federated shares: users can only be MORE restrictive, never LESS restrictive
2126+
// If parent has hideDownload=true, child MUST have hideDownload=true
2127+
$parentHidesDownload = $originalShare->getHideDownload();
2128+
2129+
// Check if download permission is available from parent
2130+
$parentAllowsDownload = $inheritedAttributes === null || $inheritedAttributes->getAttribute('permissions', 'download') !== false;
2131+
2132+
// Apply inheritance rules:
2133+
// 1. If parent hides download, child must hide download
2134+
// 2. If parent allows download, child can choose to hide or allow
2135+
// 3. If parent forbids download, child cannot allow download
2136+
$hideDownload = $parentHidesDownload || $userExplicitlySetHideDownload
2137+
2138+
$canDownload = $canDownload || $parentAllowsDownload;
2139+
21272140
} elseif ($node->getStorage()->instanceOfStorage(Storage::class)) {
21282141
$canDownload = true; // in case of federation storage, we can expect the download to be activated by default
2142+
// For external federation storage, respect user's choice if downloads are available
2143+
$hideDownload = $userExplicitlySetHideDownload;
21292144
}
21302145
}
21312146

2132-
if ($hideDownload || !$canDownload) {
2147+
// Apply the final restrictions:
2148+
// 1. If parent doesn't allow downloads at all, force hide and disable download attribute
2149+
// 2. If parent allows downloads, respect user's hideDownload choice
2150+
if (!$canDownload) {
2151+
// Parent completely forbids downloads - must enforce this restriction
21332152
$share->setHideDownload(true);
2134-
2135-
if (!$canDownload) {
2136-
$attributes = $share->getAttributes() ?? $share->newAttributes();
2137-
$attributes->setAttribute('permissions', 'download', false);
2138-
$share->setAttributes($attributes);
2139-
}
2153+
$attributes = $share->getAttributes() ?? $share->newAttributes();
2154+
$attributes->setAttribute('permissions', 'download', false);
2155+
$share->setAttributes($attributes);
2156+
} elseif ($hideDownload) {
2157+
// Either parent forces hide, or user chooses to hide - respect this
2158+
$share->setHideDownload(true);
2159+
} else {
2160+
// User explicitly wants to allow downloads and parent permits it
2161+
$share->setHideDownload(false);
21402162
}
21412163
}
21422164

0 commit comments

Comments
 (0)