From 53a3ec2f18e995b700e5c1025df9303e70de9c4a Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 19 Aug 2016 10:10:19 +0200 Subject: [PATCH] When requesting a permalink to an invalid file redirect We need to do the redirect to update address bar. --- apps/files/lib/Controller/ViewController.php | 7 +++---- apps/files/tests/Controller/ViewControllerTest.php | 10 +++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php index 776f7502d8..03ac20aa88 100644 --- a/apps/files/lib/Controller/ViewController.php +++ b/apps/files/lib/Controller/ViewController.php @@ -144,15 +144,14 @@ class ViewController extends Controller { * @param string $dir * @param string $view * @param string $fileid - * @return TemplateResponse + * @return TemplateResponse|RedirectResponse */ - public function index($dir = '', $view = '', $fileid = null) { - $fileNotFound = false; + public function index($dir = '', $view = '', $fileid = null, $fileNotFound = false) { if ($fileid !== null) { try { return $this->showFile($fileid); } catch (NotFoundException $e) { - $fileNotFound = true; + return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', ['fileNotFound' => true])); } } diff --git a/apps/files/tests/Controller/ViewControllerTest.php b/apps/files/tests/Controller/ViewControllerTest.php index 5313593afd..eb4ac1555c 100644 --- a/apps/files/tests/Controller/ViewControllerTest.php +++ b/apps/files/tests/Controller/ViewControllerTest.php @@ -388,10 +388,14 @@ class ViewControllerTest extends TestCase { ->with(123) ->will($this->returnValue([])); + $this->urlGenerator->expects($this->once()) + ->method('linkToRoute') + ->with('files.view.index', ['fileNotFound' => true]) + ->willReturn('redirect.url'); + $response = $this->viewController->index('MyDir', 'MyView', '123'); - $this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $response); - $params = $response->getParams(); - $this->assertEquals(1, $params['fileNotFound']); + $this->assertInstanceOf('OCP\AppFramework\Http\RedirectResponse', $response); + $this->assertEquals('redirect.url', $response->getRedirectURL()); } public function testShowFileRouteWithTrashedFile() {