Skip to content

Commit 22976d2

Browse files
authored
Merge pull request #59008 from nextcloud/federated-sharing-check
fix: provide `canDownload` helper for shares and use it where appropriate
2 parents 294e539 + 7f8f86a commit 22976d2

4 files changed

Lines changed: 27 additions & 12 deletions

File tree

apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use OCP\AppFramework\Http\Attribute\OpenAPI;
1919
use OCP\AppFramework\Http\Attribute\PublicPage;
2020
use OCP\AppFramework\Http\JSONResponse;
21-
use OCP\Constants;
2221
use OCP\Federation\ICloudIdManager;
2322
use OCP\HintException;
2423
use OCP\Http\Client\IClientService;
@@ -108,9 +107,9 @@ public function createFederatedShare($shareWith, $token, $password = '') {
108107
return $response;
109108
}
110109

111-
if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
110+
if (!$share->canDownload()) {
112111
$response = new JSONResponse(
113-
['message' => 'Mounting file drop not supported'],
112+
['message' => 'Mounting download restricted share is not allowed'],
114113
Http::STATUS_BAD_REQUEST
115114
);
116115
$response->throttle();

apps/files_sharing/lib/DefaultPublicShareTemplateProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function renderPage(IShare $share, string $token, string $path): Template
153153

154154
// Create the header action menu
155155
$headerActions = [];
156-
if ($view !== 'public-file-drop' && !$share->getHideDownload()) {
156+
if ($share->canDownload() && !$share->getHideDownload()) {
157157
// The download URL is used for the "download" header action as well as in some cases for the direct link
158158
$downloadUrl = $this->urlGenerator->getAbsoluteURL('/public.php/dav/files/' . $token . '/?accept=zip');
159159

lib/private/Share20/Share.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
namespace OC\Share20;
99

10+
use OCP\Constants;
1011
use OCP\Files\Cache\ICacheEntry;
1112
use OCP\Files\File;
1213
use OCP\Files\FileInfo;
@@ -586,6 +587,19 @@ public function getReminderSent(): bool {
586587
return $this->reminderSent;
587588
}
588589

590+
public function canDownload(): bool {
591+
if (($this->getPermissions() & Constants::PERMISSION_READ) === 0) {
592+
return false;
593+
}
594+
595+
$attributes = $this->getAttributes();
596+
if ($attributes?->getAttribute('permissions', 'download') === false) {
597+
return false;
598+
}
599+
600+
return true;
601+
}
602+
589603
public function canSeeContent(): bool {
590604
$shareManager = Server::get(IManager::class);
591605

@@ -595,13 +609,6 @@ public function canSeeContent(): bool {
595609
return true;
596610
}
597611

598-
// No "allow preview" header set, so we must check if
599-
// the share has not explicitly disabled download permissions
600-
$attributes = $this->getAttributes();
601-
if ($attributes?->getAttribute('permissions', 'download') === false) {
602-
return false;
603-
}
604-
605-
return true;
612+
return $this->canDownload();
606613
}
607614
}

lib/public/Share/IShare.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,15 @@ public function getReminderSent(): bool;
645645
* Check if the current user can see this share files contents.
646646
* This will check the download permissions as well as the global
647647
* admin setting to allow viewing files without downloading.
648+
*
649+
* @since 32.0.0
648650
*/
649651
public function canSeeContent(): bool;
652+
653+
/**
654+
* Check if it is allowed to download this share.
655+
*
656+
* @since 34.0.0
657+
*/
658+
public function canDownload(): bool;
650659
}

0 commit comments

Comments
 (0)