]> source.dussan.org Git - nextcloud-server.git/commitdiff
Set openfile params when following internal links
authorLouis Chemineau <louis@chmn.me>
Mon, 26 Jul 2021 14:13:49 +0000 (16:13 +0200)
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>
Tue, 27 Jul 2021 11:41:32 +0000 (11:41 +0000)
Signed-off-by: Louis Chemineau <louis@chmn.me>
apps/files/lib/Controller/ViewController.php

index d834900c5010ec7b185709bb82d3abda05b9dd73..9b8b3aec40c742795b51e9556340f6e5034991cd 100644 (file)
@@ -165,7 +165,7 @@ class ViewController extends Controller {
        public function showFile(string $fileid = null): Response {
                // This is the entry point from the `/f/{fileid}` URL which is hardcoded in the server.
                try {
-                       return $this->redirectToFile($fileid);
+                       return $this->redirectToFile($fileid, true);
                } catch (NotFoundException $e) {
                        return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true]));
                }
@@ -179,7 +179,7 @@ class ViewController extends Controller {
         * @param string $view
         * @param string $fileid
         * @param bool $fileNotFound
-        * @param string $openfile
+        * @param string $openfile - the openfile URL parameter if it was present in the initial request
         * @return TemplateResponse|RedirectResponse
         * @throws NotFoundException
         */
@@ -391,10 +391,11 @@ class ViewController extends Controller {
         * Redirects to the file list and highlight the given file id
         *
         * @param string $fileId file id to show
+        * @param bool $setOpenfile - wether or not to set the openfile URL parameter
         * @return RedirectResponse redirect response or not found response
         * @throws \OCP\Files\NotFoundException
         */
-       private function redirectToFile($fileId) {
+       private function redirectToFile($fileId, bool $setOpenfile = false) {
                $uid = $this->userSession->getUser()->getUID();
                $baseFolder = $this->rootFolder->getUserFolder($uid);
                $files = $baseFolder->getById($fileId);
@@ -416,6 +417,11 @@ class ViewController extends Controller {
                                $params['dir'] = $baseFolder->getRelativePath($file->getParent()->getPath());
                                // and scroll to the entry
                                $params['scrollto'] = $file->getName();
+
+                               if ($setOpenfile) {
+                                       // forward the openfile URL parameter.
+                                       $params['openfile'] = $fileId;
+                               }
                        }
 
                        return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));