diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2023-09-19 21:00:21 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2023-10-04 11:29:05 +0200 |
commit | b05719c8e900268a50412756c38ee19a87e67093 (patch) | |
tree | 662588950fbf9621e5e25a31e0996144219ee43c /apps | |
parent | 529bce24b44f7c10673e619fe062baeea5b5c3d5 (diff) | |
download | nextcloud-server-b05719c8e900268a50412756c38ee19a87e67093.tar.gz nextcloud-server-b05719c8e900268a50412756c38ee19a87e67093.zip |
fix: redirect to proper directory if file not found
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/lib/Controller/ViewController.php | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index d4a75b514eb..88d9a32039b 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -231,6 +231,19 @@ class ViewController extends Controller { $favElements['folders'] = []; } + // If the file doesn't exists in the folder and + // exists in only one occurrence, redirect to that file + // in the correct folder + if ($fileid && $dir !== '') { + $baseFolder = $this->rootFolder->getUserFolder($userId); + $nodes = $baseFolder->getById((int) $fileid); + $relativePath = dirname($baseFolder->getRelativePath($nodes[0]->getPath())); + // If the requested path is different from the file path + if (count($nodes) === 1 && $relativePath !== $dir) { + return $this->redirectToFile((int) $fileid); + } + } + try { // If view is files, we use the directory, otherwise we use the root storage $storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/'); @@ -380,7 +393,7 @@ class ViewController extends Controller { $uid = $this->userSession->getUser()->getUID(); $baseFolder = $this->rootFolder->getUserFolder($uid); $nodes = $baseFolder->getById($fileId); - $params = []; + $params = ['view' => 'files']; try { $this->redirectToFileIfInTrashbin($fileId); |