Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Constants;
use OCP\Federation\ICloudIdManager;
use OCP\HintException;
use OCP\Http\Client\IClientService;
Expand Down Expand Up @@ -108,9 +107,9 @@ public function createFederatedShare($shareWith, $token, $password = '') {
return $response;
}

if (($share->getPermissions() & Constants::PERMISSION_READ) === 0) {
if (!$share->canDownload()) {
$response = new JSONResponse(
['message' => 'Mounting file drop not supported'],
['message' => 'Mounting download restricted share is not allowed'],
Http::STATUS_BAD_REQUEST
);
$response->throttle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function renderPage(IShare $share, string $token, string $path): Template

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

Expand Down
23 changes: 15 additions & 8 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
namespace OC\Share20;

use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\Files\FileInfo;
Expand Down Expand Up @@ -611,6 +612,19 @@ public function getReminderSent(): bool {
return $this->reminderSent;
}

public function canDownload(): bool {
if (($this->getPermissions() & Constants::PERMISSION_READ) === 0) {
return false;
}

$attributes = $this->getAttributes();
if ($attributes?->getAttribute('permissions', 'download') === false) {
return false;
}

return true;
}

public function canSeeContent(): bool {
$shareManager = Server::get(IManager::class);

Expand All @@ -620,13 +634,6 @@ public function canSeeContent(): bool {
return true;
}

// No "allow preview" header set, so we must check if
// the share has not explicitly disabled download permissions
$attributes = $this->getAttributes();
if ($attributes?->getAttribute('permissions', 'download') === false) {
return false;
}

return true;
return $this->canDownload();
}
}
9 changes: 9 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,15 @@ public function getReminderSent(): bool;
* Check if the current user can see this share files contents.
* This will check the download permissions as well as the global
* admin setting to allow viewing files without downloading.
*
* @since 32.0.0
*/
public function canSeeContent(): bool;

/**
* Check if it is allowed to download this share.
*
* @since 32.0.7
*/
public function canDownload(): bool;
}
Loading