When requesting a permalink to an invalid file redirect

We need to do the redirect to update address bar.
This commit is contained in:
Roeland Jago Douma 2016-08-19 10:10:19 +02:00
parent ac9f75e1d9
commit 53a3ec2f18
No known key found for this signature in database
GPG Key ID: 1E152838F164D13B
2 changed files with 10 additions and 7 deletions

View File

@ -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]));
}
}

View File

@ -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() {