diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-04-04 11:33:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-04 11:33:19 +0300 |
commit | 506ca2b8be90bdfcb4cc8eacd05c92bb11ace718 (patch) | |
tree | 16e339f525f799caff644a0e6f19085ab2604ace | |
parent | a8b028eb1aeb8cd200c83f895caf89cf01976a9e (diff) | |
parent | 422ba52ecb0229c032ad0476dd13e8459477c1b5 (diff) |
Merge pull request #20147 from nextcloud/backport/20131/stable16
[stable16] Fix PDF and video viewers on public links
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareController.php | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 37a564d7654..43cf741f407 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -46,6 +46,7 @@ use OCP\AppFramework\Http\Template\ExternalShareMenuAction; use OCP\AppFramework\Http\Template\LinkMenuAction; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\Defaults; +use OCP\Files\Folder; use OCP\IL10N; use OCP\Template; use OCP\Share; @@ -527,10 +528,6 @@ class ShareController extends AuthPublicShareController { throw new NotFoundException(); } - if ($share->getHideDownload()) { - return new NotFoundResponse(); - } - $userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()); $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath()); @@ -560,11 +557,17 @@ class ShareController extends AuthPublicShareController { if ($node instanceof \OCP\Files\File) { // Single file download $this->singleFileDownloaded($share, $share->getNode()); - } else if (!empty($files_list)) { - $this->fileListDownloaded($share, $files_list, $node); } else { - // The folder is downloaded - $this->singleFileDownloaded($share, $share->getNode()); + try { + if (!empty($files_list)) { + $this->fileListDownloaded($share, $files_list, $node); + } else { + // The folder is downloaded + $this->singleFileDownloaded($share, $share->getNode()); + } + } catch (NotFoundException $e) { + return new NotFoundResponse(); + } } } @@ -616,8 +619,13 @@ class ShareController extends AuthPublicShareController { * @param Share\IShare $share * @param array $files_list * @param \OCP\Files\Folder $node + * @throws NotFoundException when trying to download a folder or multiple files of a "hide download" share */ protected function fileListDownloaded(Share\IShare $share, array $files_list, \OCP\Files\Folder $node) { + if ($share->getHideDownload() && count($files_list) > 1) { + throw new NotFoundException('Downloading more than 1 file'); + } + foreach ($files_list as $file) { $subNode = $node->get($file); $this->singleFileDownloaded($share, $subNode); @@ -629,8 +637,12 @@ class ShareController extends AuthPublicShareController { * create activity if a single file was downloaded from a link share * * @param Share\IShare $share + * @throws NotFoundException when trying to download a folder of a "hide download" share */ protected function singleFileDownloaded(Share\IShare $share, \OCP\Files\Node $node) { + if ($share->getHideDownload() && $node instanceof Folder) { + throw new NotFoundException('Downloading a folder'); + } $fileId = $node->getId(); |