-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Permalinks #24434
Permalinks #24434
Changes from all commits
093e9dd
fdeafef
112b703
caefe23
254576e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* @author Christoph Wurst <[email protected]> | ||
* @author Lukas Reschke <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* @author Vincent Petry <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
|
@@ -26,6 +27,7 @@ | |
use OC\AppFramework\Http\Request; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\ContentSecurityPolicy; | ||
use OCP\AppFramework\Http\Response; | ||
use OCP\AppFramework\Http\RedirectResponse; | ||
use OCP\AppFramework\Http\TemplateResponse; | ||
use OCP\IConfig; | ||
|
@@ -35,6 +37,8 @@ | |
use OCP\IURLGenerator; | ||
use OCP\IUserSession; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use OCP\AppFramework\Http\NotFoundResponse; | ||
use OCP\Files\Folder; | ||
|
||
/** | ||
* Class ViewController | ||
|
@@ -58,6 +62,8 @@ class ViewController extends Controller { | |
protected $eventDispatcher; | ||
/** @var IUserSession */ | ||
protected $userSession; | ||
/** @var \OCP\Files\Folder */ | ||
protected $userFolder; | ||
|
||
/** | ||
* @param string $appName | ||
|
@@ -68,6 +74,7 @@ class ViewController extends Controller { | |
* @param IConfig $config | ||
* @param EventDispatcherInterface $eventDispatcherInterface | ||
* @param IUserSession $userSession | ||
* @param Folder $userFolder | ||
*/ | ||
public function __construct($appName, | ||
IRequest $request, | ||
|
@@ -76,7 +83,9 @@ public function __construct($appName, | |
IL10N $l10n, | ||
IConfig $config, | ||
EventDispatcherInterface $eventDispatcherInterface, | ||
IUserSession $userSession) { | ||
IUserSession $userSession, | ||
Folder $userFolder | ||
) { | ||
parent::__construct($appName, $request); | ||
$this->appName = $appName; | ||
$this->request = $request; | ||
|
@@ -86,6 +95,7 @@ public function __construct($appName, | |
$this->config = $config; | ||
$this->eventDispatcher = $eventDispatcherInterface; | ||
$this->userSession = $userSession; | ||
$this->userFolder = $userFolder; | ||
} | ||
|
||
/** | ||
|
@@ -124,10 +134,15 @@ protected function getStorageInfo() { | |
* | ||
* @param string $dir | ||
* @param string $view | ||
* @param string $fileid | ||
* @return TemplateResponse | ||
* @throws \OCP\Files\NotFoundException | ||
*/ | ||
public function index($dir = '', $view = '') { | ||
public function index($dir = '', $view = '', $fileid = null) { | ||
if ($fileid !== null) { | ||
return $this->showFile($fileid); | ||
} | ||
|
||
$nav = new \OCP\Template('files', 'appnavigation', ''); | ||
|
||
// Load the files we need | ||
|
@@ -239,4 +254,33 @@ public function index($dir = '', $view = '') { | |
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Redirects to the file list and highlight the given file id | ||
* | ||
* @param string $fileId file id to show | ||
* @return Response redirect response or not found response | ||
* | ||
* @NoCSRFRequired | ||
* @NoAdminRequired | ||
*/ | ||
public function showFile($fileId) { | ||
$files = $this->userFolder->getById($fileId); | ||
$params = []; | ||
|
||
if (!empty($files)) { | ||
$file = current($files); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking... maybe it is good to loop over all files (if a file is shared via multiple ways)... and pick the one with the highest permission? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course harder then it sounds because which do you pick if 1 has edit and 1 has share permissions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not that common scenario... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rullzer yeah good point, possibly something for later. Also I thought about adding a "trashbin" route in case the file is detected in trash instead, but something for later also. |
||
if ($file instanceof Folder) { | ||
// set the full path to enter the folder | ||
$params['dir'] = $this->userFolder->getRelativePath($file->getPath()); | ||
} else { | ||
// set parent path as dir | ||
$params['dir'] = $this->userFolder->getRelativePath($file->getParent()->getPath()); | ||
// and scroll to the entry | ||
$params['scrollto'] = $file->getName(); | ||
} | ||
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index', $params)); | ||
} | ||
return new NotFoundResponse(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So fileid always has preference if it is there. Sounds good