diff options
author | Vincent Petry <vincent@nextcloud.com> | 2022-06-13 13:48:35 +0300 |
---|---|---|
committer | Carl Schwan <carl@carlschwan.eu> | 2022-08-03 14:24:20 +0300 |
commit | cc7564758b22b424ddcaa2fe7d856e647b33bfd4 (patch) | |
tree | 9e378a3b5e5493228cd438d8284b4186daaaeb12 /apps/files_sharing | |
parent | ef6e4fc52d7b870189624b7200681c70718d8983 (diff) |
Fix view-only code after code review comments
Signed-off-by: Vincent Petry <vincent@nextcloud.com>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/AppInfo/Application.php | 10 | ||||
-rw-r--r-- | apps/files_sharing/lib/ViewOnly.php | 13 |
2 files changed, 14 insertions, 9 deletions
diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index c40dfc98b52..97bb9447713 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -124,12 +124,12 @@ class Application extends App implements IBootstrap { } - public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider) { + public function registerMountProviders(IMountProviderCollection $mountProviderCollection, MountProvider $mountProvider, ExternalMountProvider $externalMountProvider): void { $mountProviderCollection->registerProvider($mountProvider); $mountProviderCollection->registerProvider($externalMountProvider); } - public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher) { + public function registerEventsScripts(IEventDispatcher $dispatcher, EventDispatcherInterface $oldDispatcher): void { // sidebar and files scripts $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalListener::class); $dispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, LegacyBeforeTemplateRenderedListener::class); @@ -158,12 +158,12 @@ class Application extends App implements IBootstrap { IEventDispatcher $dispatcher, ?IUserSession $userSession, IRootFolder $rootFolder - ) { + ): void { $dispatcher->addListener( 'file.beforeGetDirect', function (GenericEvent $event) use ($userSession, $rootFolder) { - $pathsToCheck[] = $event->getArgument('path'); + $pathsToCheck = [$event->getArgument('path')]; // Check only for user/group shares. Don't restrict e.g. share links if ($userSession && $userSession->isLoggedIn()) { @@ -212,7 +212,7 @@ class Application extends App implements IBootstrap { ); } - public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession) { + public function setupSharingMenus(IManager $shareManager, IFactory $l10nFactory, IUserSession $userSession): void { if (!$shareManager->shareApiEnabled() || !class_exists('\OCA\Files\App')) { return; } diff --git a/apps/files_sharing/lib/ViewOnly.php b/apps/files_sharing/lib/ViewOnly.php index 58ff2e7f2b4..26e8e43a871 100644 --- a/apps/files_sharing/lib/ViewOnly.php +++ b/apps/files_sharing/lib/ViewOnly.php @@ -42,7 +42,7 @@ class ViewOnly { * @param string[] $pathsToCheck * @return bool */ - public function check($pathsToCheck) { + public function check(array $pathsToCheck): bool { // If any of elements cannot be downloaded, prevent whole download foreach ($pathsToCheck as $file) { try { @@ -70,7 +70,7 @@ class ViewOnly { * @return bool * @throws NotFoundException */ - private function dirRecursiveCheck(Folder $dirInfo) { + private function dirRecursiveCheck(Folder $dirInfo): bool { if (!$this->checkFileInfo($dirInfo)) { return false; } @@ -94,7 +94,7 @@ class ViewOnly { * @return bool * @throws NotFoundException */ - private function checkFileInfo(Node $fileInfo) { + private function checkFileInfo(Node $fileInfo): bool { // Restrict view-only to nodes which are shared $storage = $fileInfo->getStorage(); if (!$storage->instanceOfStorage(SharedStorage::class)) { @@ -105,9 +105,14 @@ class ViewOnly { /** @var \OCA\Files_Sharing\SharedStorage $storage */ $share = $storage->getShare(); + $canDownload = true; + // Check if read-only and on whether permission can download is both set and disabled. + $attributes = $share->getAttributes(); + if ($attributes !== null) { + $canDownload = $attributes->getAttribute('permissions', 'download'); + } - $canDownload = $share->getAttributes()->getAttribute('permissions', 'download'); if ($canDownload !== null && !$canDownload) { return false; } |