Merge pull request #25001 from owncloud/issue-24939-better-ux-on-invalid-perma-link
Improve the UX for "not found" perma links
This commit is contained in:
commit
652b4961f2
|
@ -53,6 +53,9 @@
|
||||||
this.$showHiddenFiles = $('input#showhiddenfilesToggle');
|
this.$showHiddenFiles = $('input#showhiddenfilesToggle');
|
||||||
var showHidden = $('#showHiddenFiles').val() === "1";
|
var showHidden = $('#showHiddenFiles').val() === "1";
|
||||||
this.$showHiddenFiles.prop('checked', showHidden);
|
this.$showHiddenFiles.prop('checked', showHidden);
|
||||||
|
if ($('#fileNotFound').val() === "1") {
|
||||||
|
OC.Notification.showTemporary(t('files', 'File could not be found'));
|
||||||
|
}
|
||||||
|
|
||||||
this._filesConfig = new OC.Backbone.Model({
|
this._filesConfig = new OC.Backbone.Model({
|
||||||
showhidden: showHidden
|
showhidden: showHidden
|
||||||
|
|
|
@ -27,9 +27,9 @@ namespace OCA\Files\Controller;
|
||||||
use OC\AppFramework\Http\Request;
|
use OC\AppFramework\Http\Request;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
use OCP\AppFramework\Http\ContentSecurityPolicy;
|
||||||
use OCP\AppFramework\Http\Response;
|
|
||||||
use OCP\AppFramework\Http\RedirectResponse;
|
use OCP\AppFramework\Http\RedirectResponse;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\INavigationManager;
|
use OCP\INavigationManager;
|
||||||
|
@ -37,7 +37,6 @@ use OCP\IRequest;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use OCP\AppFramework\Http\NotFoundResponse;
|
|
||||||
use OCP\Files\Folder;
|
use OCP\Files\Folder;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
|
|
||||||
|
@ -142,11 +141,15 @@ class ViewController extends Controller {
|
||||||
* @param string $view
|
* @param string $view
|
||||||
* @param string $fileid
|
* @param string $fileid
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
* @throws \OCP\Files\NotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function index($dir = '', $view = '', $fileid = null) {
|
public function index($dir = '', $view = '', $fileid = null) {
|
||||||
|
$fileNotFound = false;
|
||||||
if ($fileid !== null) {
|
if ($fileid !== null) {
|
||||||
|
try {
|
||||||
return $this->showFile($fileid);
|
return $this->showFile($fileid);
|
||||||
|
} catch (NotFoundException $e) {
|
||||||
|
$fileNotFound = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$nav = new \OCP\Template('files', 'appnavigation', '');
|
$nav = new \OCP\Template('files', 'appnavigation', '');
|
||||||
|
@ -245,6 +248,7 @@ class ViewController extends Controller {
|
||||||
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
||||||
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
$showHidden = (bool) $this->config->getUserValue($this->userSession->getUser()->getUID(), 'files', 'show_hidden', false);
|
||||||
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
|
||||||
|
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
|
||||||
$params['appNavigation'] = $nav;
|
$params['appNavigation'] = $nav;
|
||||||
$params['appContents'] = $contentItems;
|
$params['appContents'] = $contentItems;
|
||||||
$this->navigationManager->setActiveEntry('files_index');
|
$this->navigationManager->setActiveEntry('files_index');
|
||||||
|
@ -265,13 +269,13 @@ class ViewController extends Controller {
|
||||||
* Redirects to the file list and highlight the given file id
|
* Redirects to the file list and highlight the given file id
|
||||||
*
|
*
|
||||||
* @param string $fileId file id to show
|
* @param string $fileId file id to show
|
||||||
* @return Response redirect response or not found response
|
* @return RedirectResponse redirect response or not found response
|
||||||
|
* @throws \OCP\Files\NotFoundException
|
||||||
*
|
*
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
*/
|
*/
|
||||||
public function showFile($fileId) {
|
public function showFile($fileId) {
|
||||||
try {
|
|
||||||
$uid = $this->userSession->getUser()->getUID();
|
$uid = $this->userSession->getUser()->getUID();
|
||||||
$baseFolder = $this->rootFolder->get($uid . '/files/');
|
$baseFolder = $this->rootFolder->get($uid . '/files/');
|
||||||
$files = $baseFolder->getById($fileId);
|
$files = $baseFolder->getById($fileId);
|
||||||
|
@ -296,9 +300,6 @@ class ViewController extends Controller {
|
||||||
}
|
}
|
||||||
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params));
|
||||||
}
|
}
|
||||||
} catch (\OCP\Files\NotFoundException $e) {
|
throw new \OCP\Files\NotFoundException();
|
||||||
return new NotFoundResponse();
|
|
||||||
}
|
|
||||||
return new NotFoundResponse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
<input type="hidden" name="usedSpacePercent" id="usedSpacePercent" value="<?php p($_['usedSpacePercent']); ?>" />
|
<input type="hidden" name="usedSpacePercent" id="usedSpacePercent" value="<?php p($_['usedSpacePercent']); ?>" />
|
||||||
<input type="hidden" name="owner" id="owner" value="<?php p($_['owner']); ?>" />
|
<input type="hidden" name="owner" id="owner" value="<?php p($_['owner']); ?>" />
|
||||||
<input type="hidden" name="ownerDisplayName" id="ownerDisplayName" value="<?php p($_['ownerDisplayName']); ?>" />
|
<input type="hidden" name="ownerDisplayName" id="ownerDisplayName" value="<?php p($_['ownerDisplayName']); ?>" />
|
||||||
|
<input type="hidden" name="fileNotFound" id="fileNotFound" value="<?php p($_['fileNotFound']); ?>"" />
|
||||||
<?php if (!$_['isPublic']) :?>
|
<?php if (!$_['isPublic']) :?>
|
||||||
<input type="hidden" name="mailNotificationEnabled" id="mailNotificationEnabled" value="<?php p($_['mailNotificationEnabled']) ?>" />
|
<input type="hidden" name="mailNotificationEnabled" id="mailNotificationEnabled" value="<?php p($_['mailNotificationEnabled']) ?>" />
|
||||||
<input type="hidden" name="mailPublicNotificationEnabled" id="mailPublicNotificationEnabled" value="<?php p($_['mailPublicNotificationEnabled']) ?>" />
|
<input type="hidden" name="mailPublicNotificationEnabled" id="mailPublicNotificationEnabled" value="<?php p($_['mailPublicNotificationEnabled']) ?>" />
|
||||||
|
|
|
@ -26,6 +26,7 @@ namespace OCA\Files\Tests\Controller;
|
||||||
|
|
||||||
use OCA\Files\Controller\ViewController;
|
use OCA\Files\Controller\ViewController;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\Template;
|
use OCP\Template;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
@ -259,7 +260,8 @@ class ViewControllerTest extends TestCase {
|
||||||
'isPublic' => false,
|
'isPublic' => false,
|
||||||
'defaultFileSorting' => 'name',
|
'defaultFileSorting' => 'name',
|
||||||
'defaultFileSortingDirection' => 'asc',
|
'defaultFileSortingDirection' => 'asc',
|
||||||
'showHiddenFiles' => false,
|
'showHiddenFiles' => 0,
|
||||||
|
'fileNotFound' => 0,
|
||||||
'mailNotificationEnabled' => 'no',
|
'mailNotificationEnabled' => 'no',
|
||||||
'mailPublicNotificationEnabled' => 'no',
|
'mailPublicNotificationEnabled' => 'no',
|
||||||
'allowShareWithLink' => 'yes',
|
'allowShareWithLink' => 'yes',
|
||||||
|
@ -410,11 +412,14 @@ class ViewControllerTest extends TestCase {
|
||||||
->with(123)
|
->with(123)
|
||||||
->will($this->returnValue([]));
|
->will($this->returnValue([]));
|
||||||
|
|
||||||
$expected = new Http\NotFoundResponse();
|
|
||||||
if ($useShowFile) {
|
if ($useShowFile) {
|
||||||
$this->assertEquals($expected, $this->viewController->showFile(123));
|
$this->setExpectedException('OCP\Files\NotFoundException');
|
||||||
|
$this->viewController->showFile(123);
|
||||||
} else {
|
} else {
|
||||||
$this->assertEquals($expected, $this->viewController->index('/whatever', '', '123'));
|
$response = $this->viewController->index('MyDir', 'MyView', '123');
|
||||||
|
$this->assertInstanceOf('OCP\AppFramework\Http\TemplateResponse', $response);
|
||||||
|
$params = $response->getParams();
|
||||||
|
$this->assertEquals(1, $params['fileNotFound']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue