diff options
author | Julius Härtl <jus@bitgrid.net> | 2023-02-15 16:16:54 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-02-20 12:16:34 +0100 |
commit | 614981ae9abbfed04b9d1b3663f7e9d0aa85404c (patch) | |
tree | a10819a57f5f7a04a2fbf8430b5c5f37cf01120b /lib/private | |
parent | 6bb0985e59d7ba3c4cf9928d8bb766ac9975cd12 (diff) | |
download | nextcloud-server-614981ae9abbfed04b9d1b3663f7e9d0aa85404c.tar.gz nextcloud-server-614981ae9abbfed04b9d1b3663f7e9d0aa85404c.zip |
feat(directediting): Allow opening by file id
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index 039944e2491..2dd2abe5408 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -26,10 +26,11 @@ namespace OC\DirectEditing; use Doctrine\DBAL\FetchMode; -use OC\Files\Node\Folder; +use \OCP\Files\Folder; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\TemplateResponse; +use OCP\Constants; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DirectEditing\ACreateFromTemplate; use OCP\DirectEditing\IEditor; @@ -152,9 +153,25 @@ class Manager implements IManager { throw new \RuntimeException('No creator found'); } - public function open(string $filePath, string $editorId = null): string { - /** @var File $file */ - $file = $this->rootFolder->getUserFolder($this->userId)->get($filePath); + public function open(string $filePath, string $editorId = null, ?int $fileId = null): string { + $userFolder = $this->rootFolder->getUserFolder($this->userId); + $file = $userFolder->get($filePath); + if ($fileId !== null && $file instanceof Folder) { + $files = $file->getById($fileId); + + // Workaround to always open files with edit permissions if multiple occurences of + // the same file id are in the user home, ideally we should also track the path of the file when opening + usort($files, function (Node $a, Node $b) { + return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE); + }); + $file = array_shift($files); + } + + if (!$file instanceof File) { + throw new NotFoundException(); + } + + $filePath = $userFolder->getRelativePath($file->getPath()); if ($editorId === null) { $editorId = $this->findEditorForFile($file); |