Skip to content

Commit a32def2

Browse files
committed
fix(sharing): Allow users to control 'Hide download' setting on federated 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
1 parent 09eb205 commit a32def2

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

apps/files_sharing/lib/Controller/ShareAPIController.php

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

21242124
$canDownload = false;
21252125
$hideDownload = true;
2126+
$userExplicitlySetHideDownload = $share->getHideDownload(); // Capture user's explicit choice
21262127

21272128
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
21282129
$nodes = $userFolder->getById($share->getNodeId());
@@ -2148,23 +2149,48 @@ private function checkInheritedAttributes(IShare $share): void {
21482149
/** @var SharedStorage $storage */
21492150
$originalShare = $storage->getShare();
21502151
$inheritedAttributes = $originalShare->getAttributes();
2151-
// hide if hidden and also the current share enforces hide (can only be false if one share is false or user is owner)
2152-
$hideDownload = $hideDownload && $originalShare->getHideDownload();
2153-
// allow download if already allowed by previous share or when the current share allows downloading
2154-
$canDownload = $canDownload || $inheritedAttributes === null || $inheritedAttributes->getAttribute('permissions', 'download') !== false;
2152+
2153+
// For federated shares: users can only be MORE restrictive, never LESS restrictive
2154+
// If parent has hideDownload=true, child MUST have hideDownload=true
2155+
$parentHidesDownload = $originalShare->getHideDownload();
2156+
2157+
// Check if download permission is available from parent
2158+
$parentAllowsDownload = $inheritedAttributes === null || $inheritedAttributes->getAttribute('permissions', 'download') !== false;
2159+
2160+
// Apply inheritance rules:
2161+
// 1. If parent hides download, child must hide download
2162+
// 2. If parent allows download, child can choose to hide or allow
2163+
// 3. If parent forbids download, child cannot allow download
2164+
if ($parentHidesDownload) {
2165+
$hideDownload = true; // Parent forces hide, child cannot override
2166+
} else {
2167+
$hideDownload = $userExplicitlySetHideDownload; // Respect user's choice when parent allows
2168+
}
2169+
2170+
$canDownload = $canDownload || $parentAllowsDownload;
2171+
21552172
} elseif ($node->getStorage()->instanceOfStorage(Storage::class)) {
21562173
$canDownload = true; // in case of federation storage, we can expect the download to be activated by default
2174+
// For external federation storage, respect user's choice if downloads are available
2175+
$hideDownload = $userExplicitlySetHideDownload;
21572176
}
21582177
}
21592178

2160-
if ($hideDownload || !$canDownload) {
2179+
// Apply the final restrictions:
2180+
// 1. If parent doesn't allow downloads at all, force hide and disable download attribute
2181+
// 2. If parent allows downloads, respect user's hideDownload choice
2182+
if (!$canDownload) {
2183+
// Parent completely forbids downloads - must enforce this restriction
21612184
$share->setHideDownload(true);
2162-
2163-
if (!$canDownload) {
2164-
$attributes = $share->getAttributes() ?? $share->newAttributes();
2165-
$attributes->setAttribute('permissions', 'download', false);
2166-
$share->setAttributes($attributes);
2167-
}
2185+
$attributes = $share->getAttributes() ?? $share->newAttributes();
2186+
$attributes->setAttribute('permissions', 'download', false);
2187+
$share->setAttributes($attributes);
2188+
} elseif ($hideDownload) {
2189+
// Either parent forces hide, or user chooses to hide - respect this
2190+
$share->setHideDownload(true);
2191+
} else {
2192+
// User explicitly wants to allow downloads and parent permits it
2193+
$share->setHideDownload(false);
21682194
}
21692195
}
21702196

0 commit comments

Comments
 (0)