Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set openfile params when following internal links #28174

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand All @@ -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
*/
Expand Down Expand Up @@ -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 - whether 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);
Expand All @@ -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));
Expand Down