feat(share): provide canDownload getter on the share

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2026-03-17 17:01:58 +01:00
parent 3961a8be67
commit 08495bfc0e
No known key found for this signature in database
GPG key ID: 7E849AE05218500F
2 changed files with 24 additions and 8 deletions

View file

@ -7,6 +7,7 @@
*/
namespace OC\Share20;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\File;
use OCP\Files\FileInfo;
@ -586,6 +587,19 @@ class Share implements IShare {
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);
@ -595,13 +609,6 @@ class Share implements IShare {
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();
}
}

View file

@ -645,6 +645,15 @@ interface IShare {
* 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 34.0.0
*/
public function canDownload(): bool;
}