From e558a004966e2603b19ae2f0e084f1de8c9e070e Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Mon, 26 Jul 2021 16:13:49 +0200 Subject: [PATCH 1/2] Set openfile params when following internal links Signed-off-by: Louis Chemineau --- apps/files/lib/Controller/ViewController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index d834900c5010e..9b8b3aec40c74 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -165,7 +165,7 @@ protected function getStorageInfo() { 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 @@ public function showFile(string $fileid = null): Response { * @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 @@ private function provideInitialState(string $dir, ?string $openfile): void { * 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 @@ private function redirectToFile($fileId) { $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)); From 1ad5e8ad73edc60e3cdb67115e652f9df8915a6a Mon Sep 17 00:00:00 2001 From: Louis <6653109+artonge@users.noreply.github.com> Date: Wed, 28 Jul 2021 11:15:03 +0200 Subject: [PATCH 2/2] Fix typo Co-authored-by: Pytal <24800714+Pytal@users.noreply.github.com> --- apps/files/lib/Controller/ViewController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 9b8b3aec40c74..64ebbea0cfb8d 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -391,7 +391,7 @@ private function provideInitialState(string $dir, ?string $openfile): void { * 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 + * @param bool $setOpenfile - whether or not to set the openfile URL parameter * @return RedirectResponse redirect response or not found response * @throws \OCP\Files\NotFoundException */