diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 54223c57e2d..3c395caec4b 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -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(); } } diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index c038820551c..da8b9e4868a 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -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; }