Skip to content

Commit 08495bf

Browse files
committed
feat(share): provide canDownload getter on the share
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 3961a8b commit 08495bf

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

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)