diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-08-04 18:04:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-04 18:04:42 +0300 |
commit | 5b2cb1bb48038552533a2925be2a74f1ec0d5ec2 (patch) | |
tree | 2f6414cb8715e009236f71fb86bcdbb033496c9a | |
parent | c6dff61a27a37aa2343c96624f818e9b7d93559a (diff) | |
parent | 6f904ca04b7b2c238220a9c64607c5142836e397 (diff) |
Merge pull request #2280 from nextcloud/enh/2267/prevent-download
Prevent download on user shares
-rw-r--r-- | lib/TokenManager.php | 20 | ||||
-rw-r--r-- | tests/stub.phpstub | 6 |
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/TokenManager.php b/lib/TokenManager.php index 95a81081..cd92059f 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 @@ class TokenManager { } } } + + // 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 8677eefa..8b53b34d 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; |