diff --git a/lib/TokenManager.php b/lib/TokenManager.php index 95a81081a1..cd92059f1d 100644 --- a/lib/TokenManager.php +++ b/lib/TokenManager.php @@ -22,6 +22,7 @@ namespace OCA\Richdocuments; use OC\Files\Filesystem; +use OCA\Files_Sharing\SharedStorage; use OCA\Richdocuments\Db\Direct; use OCA\Richdocuments\Db\WopiMapper; use OCA\Richdocuments\Db\Wopi; @@ -147,6 +148,25 @@ public function getToken($fileId, $shareToken = null, $editoruid = null, $direct } } } + + // disable download if at least one shared access has it disabled + + foreach ($files as $file) { + $storage = $file->getStorage(); + // using string as we have no guarantee that "files_sharing" app is loaded + if ($storage->instanceOfStorage(SharedStorage::class)) { + if (!method_exists(SharedStorage::class, 'getAttributes')) { + break; + } + /** @var SharedStorage $storage */ + $share = $storage->getShare(); + $canDownload = $share->getAttributes()->getAttribute('permissions', 'download'); + if ($canDownload !== null && !$canDownload) { + $hideDownload = true; + break; + } + } + } } catch (\Exception $e) { throw $e; } diff --git a/tests/stub.phpstub b/tests/stub.phpstub index 8677eefafd..8b53b34d2e 100644 --- a/tests/stub.phpstub +++ b/tests/stub.phpstub @@ -17,6 +17,12 @@ namespace Doctrine\DBAL\Platforms { class SqlitePlatform {} } +namespace OCA\Files_Sharing { + use \OCP\Share\IShare; + class SharedStorage { + public function getShare(): IShare {} + } +} namespace OCA\Files_Sharing\Event { use \OCP\Share\IShare;