diff options
Diffstat (limited to 'apps/files_sharing/lib/Controller/ShareController.php')
-rw-r--r-- | apps/files_sharing/lib/Controller/ShareController.php | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/apps/files_sharing/lib/Controller/ShareController.php b/apps/files_sharing/lib/Controller/ShareController.php index 9a8e1298f93..29ed242a975 100644 --- a/apps/files_sharing/lib/Controller/ShareController.php +++ b/apps/files_sharing/lib/Controller/ShareController.php @@ -61,7 +61,6 @@ use OCA\Files_Sharing\Activity\Providers\Downloads; use OCP\Files\NotFoundException; use OCP\Files\IRootFolder; use OCP\Share\Exceptions\ShareNotFound; -use OCP\Util; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; use OCP\Share\IManager as ShareManager; @@ -295,9 +294,12 @@ class ShareController extends AuthPublicShareController { if (!$this->validateShare($share)) { throw new NotFoundException(); } + + $shareNode = $share->getNode(); + // We can't get the path of a file share try { - if ($share->getNode() instanceof \OCP\Files\File && $path !== '') { + if ($shareNode instanceof \OCP\Files\File && $path !== '') { $this->emitAccessShareHook($share, 404, 'Share not found'); throw new NotFoundException(); } @@ -309,34 +311,34 @@ class ShareController extends AuthPublicShareController { $shareTmpl = []; $shareTmpl['displayName'] = $this->userManager->get($share->getShareOwner())->getDisplayName(); $shareTmpl['owner'] = $share->getShareOwner(); - $shareTmpl['filename'] = $share->getNode()->getName(); + $shareTmpl['filename'] = $shareNode->getName(); $shareTmpl['directory_path'] = $share->getTarget(); $shareTmpl['note'] = $share->getNote(); - $shareTmpl['mimetype'] = $share->getNode()->getMimetype(); - $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype()); + $shareTmpl['mimetype'] = $shareNode->getMimetype(); + $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($shareNode->getMimetype()); $shareTmpl['dirToken'] = $this->getToken(); $shareTmpl['sharingToken'] = $this->getToken(); $shareTmpl['server2serversharing'] = $this->federatedShareProvider->isOutgoingServer2serverShareEnabled(); $shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false'; $shareTmpl['dir'] = ''; - $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize(); - $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize()); + $shareTmpl['nonHumanFileSize'] = $shareNode->getSize(); + $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($shareNode->getSize()); $shareTmpl['hideDownload'] = $share->getHideDownload(); - // Show file list $hideFileList = false; - if ($share->getNode() instanceof \OCP\Files\Folder) { - /** @var \OCP\Files\Folder $rootFolder */ - $rootFolder = $share->getNode(); + + if ($shareNode instanceof \OCP\Files\Folder) { + + $shareIsFolder = true; try { - $folderNode = $rootFolder->get($path); + $folderNode = $shareNode->get($path); } catch (\OCP\Files\NotFoundException $e) { $this->emitAccessShareHook($share, 404, 'Share not found'); throw new NotFoundException(); } - $shareTmpl['dir'] = $rootFolder->getRelativePath($folderNode->getPath()); + $shareTmpl['dir'] = $shareNode->getRelativePath($folderNode->getPath()); /* * The OC_Util methods require a view. This just uses the node API @@ -352,7 +354,7 @@ class ShareController extends AuthPublicShareController { $maxUploadFilesize = $freeSpace; $folder = new Template('files', 'list', ''); - $folder->assign('dir', $rootFolder->getRelativePath($folderNode->getPath())); + $folder->assign('dir', $shareNode->getRelativePath($folderNode->getPath())); $folder->assign('dirToken', $this->getToken()); $folder->assign('permissions', \OCP\Constants::PERMISSION_READ); $folder->assign('isPublic', true); @@ -365,6 +367,8 @@ class ShareController extends AuthPublicShareController { $folder->assign('usedSpacePercent', 0); $folder->assign('trash', false); $shareTmpl['folder'] = $folder->fetchPage(); + } else { + $shareIsFolder = false; } $shareTmpl['showgridview'] = true; @@ -379,14 +383,14 @@ class ShareController extends AuthPublicShareController { $shareTmpl['previewMaxY'] = $this->config->getSystemValue('preview_max_y', 1024); $shareTmpl['disclaimer'] = $this->config->getAppValue('core', 'shareapi_public_link_disclaimertext', null); $shareTmpl['previewURL'] = $shareTmpl['downloadURL']; - $ogPreview = ''; + if ($shareTmpl['previewSupported']) { $shareTmpl['previewImage'] = $this->urlGenerator->linkToRouteAbsolute( 'files_sharing.PublicPreview.getPreview', ['x' => 200, 'y' => 200, 'file' => $shareTmpl['directory_path'], 'token' => $shareTmpl['dirToken']]); $ogPreview = $shareTmpl['previewImage']; // We just have direct previews for image files - if ($share->getNode()->getMimePart() === 'image') { + if ($shareNode->getMimePart() === 'image') { $shareTmpl['previewURL'] = $this->urlGenerator->linkToRouteAbsolute('files_sharing.publicpreview.directLink', ['token' => $this->getToken()]); $ogPreview = $shareTmpl['previewURL']; @@ -411,7 +415,6 @@ class ShareController extends AuthPublicShareController { \OCP\Util::addStyle('files_sharing', 'publicView'); \OCP\Util::addScript('files_sharing', 'public'); \OCP\Util::addScript('files_sharing', 'templates'); - \OCP\Util::addScript('files_sharing', 'public_note'); \OCP\Util::addScript('files', 'fileactions'); \OCP\Util::addScript('files', 'fileactionsmenu'); \OCP\Util::addScript('files', 'jquery.fileupload'); @@ -447,7 +450,11 @@ class ShareController extends AuthPublicShareController { $response = new PublicTemplateResponse($this->appName, 'public', $shareTmpl); $response->setHeaderTitle($shareTmpl['filename']); $response->setHeaderDetails($this->l10n->t('shared by %s', [$shareTmpl['displayName']])); - if (!$share->getHideDownload()) { + + $isNoneFileDropFolder = $shareIsFolder === false || $share->getPermissions() !== \OCP\Constants::PERMISSION_CREATE; + + if ($isNoneFileDropFolder && !$share->getHideDownload()) { + \OCP\Util::addScript('files_sharing', 'public_note'); $response->setHeaderActions([ new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $shareTmpl['downloadURL'], 0), new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $shareTmpl['downloadURL'], 10, $shareTmpl['fileSize']), |