diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-12-11 11:17:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-11 11:17:26 +0100 |
commit | 9a40ccfbf0c2f4fc3f6dd13ebdb405e048959a0e (patch) | |
tree | 24c8817f5b6fa2811bc0e1f4fc66a0b936856a59 /lib | |
parent | 2164ef045f88533cb3ca1df3881c3cb6b78e9018 (diff) | |
parent | e29a76bc79dc252b5659e38287f07c56ffa3e314 (diff) | |
download | nextcloud-server-9a40ccfbf0c2f4fc3f6dd13ebdb405e048959a0e.tar.gz nextcloud-server-9a40ccfbf0c2f4fc3f6dd13ebdb405e048959a0e.zip |
Merge pull request #18224 from nextcloud/bugfix/noid/direct-editing-path
Use file path for direct editing
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 1 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 1 | ||||
-rw-r--r-- | lib/private/DirectEditing/Manager.php | 34 | ||||
-rw-r--r-- | lib/private/DirectEditing/Token.php | 2 | ||||
-rw-r--r-- | lib/public/DirectEditing/IToken.php | 2 |
5 files changed, 28 insertions, 12 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 563d7cf7c72..f8d95a76c68 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -807,6 +807,7 @@ return array( 'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => $baseDir . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => $baseDir . '/core/Migrations/Version18000Date20191014105105.php', + 'OC\\Core\\Migrations\\Version18000Date20191204114856' => $baseDir . '/core/Migrations/Version18000Date20191204114856.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 140ec461857..91bf56af1ef 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -836,6 +836,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php', 'OC\\Core\\Migrations\\Version18000Date20190920085628' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Migrations\\Version18000Date20191014105105' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191014105105.php', + 'OC\\Core\\Migrations\\Version18000Date20191204114856' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20191204114856.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index e9bd6f2933c..fcaaf9e0303 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -37,6 +37,7 @@ use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\File; use OCP\Files\IRootFolder; +use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IDBConnection; use OCP\IUserSession; @@ -104,25 +105,21 @@ class Manager implements IManager { foreach ($creators as $creator) { if ($creator->getId() === $creatorId) { $creator->create($file, $creatorId, $templateId); - return $this->createToken($editorId, $file); + return $this->createToken($editorId, $file, $path); } } throw new \RuntimeException('No creator found'); } - public function open(int $fileId, string $editorId = null): string { - $file = $this->rootFolder->getUserFolder($this->userId)->getById($fileId); - if (count($file) === 0 || !($file[0] instanceof File) || $file === null) { - throw new NotFoundException(); - } + public function open(string $filePath, string $editorId = null): string { /** @var File $file */ - $file = $file[0]; + $file = $this->rootFolder->getUserFolder($this->userId)->get($filePath); if ($editorId === null) { $editorId = $this->findEditorForFile($file); } - return $this->createToken($editorId, $file); + return $this->createToken($editorId, $file, $filePath); } private function findEditorForFile(File $file) { @@ -213,7 +210,7 @@ class Manager implements IManager { \OC_User::setUserId($userId); } - public function createToken($editorId, File $file, IShare $share = null): string { + public function createToken($editorId, File $file, string $filePath, IShare $share = null): string { $token = $this->random->generate(64, ISecureRandom::CHAR_HUMAN_READABLE); $query = $this->connection->getQueryBuilder(); $query->insert(self::TABLE_TOKENS) @@ -221,6 +218,7 @@ class Manager implements IManager { 'token' => $query->createNamedParameter($token), 'editor_id' => $query->createNamedParameter($editorId), 'file_id' => $query->createNamedParameter($file->getId()), + 'file_path' => $query->createNamedParameter($filePath), 'user_id' => $query->createNamedParameter($this->userId), 'share_id' => $query->createNamedParameter($share !== null ? $share->getId(): null), 'timestamp' => $query->createNamedParameter(time()) @@ -229,9 +227,23 @@ class Manager implements IManager { return $token; } - public function getFileForToken($userId, $fileId) { + /** + * @param $userId + * @param $fileId + * @param null $filePath + * @return Node + * @throws NotFoundException + */ + public function getFileForToken($userId, $fileId, $filePath = null): Node { $userFolder = $this->rootFolder->getUserFolder($userId); - return $userFolder->getById($fileId)[0]; + if ($filePath !== null) { + return $userFolder->get($filePath); + } + $files = $userFolder->getById($fileId); + if (count($files) === 0) { + throw new NotFoundException('File nound found by id ' . $fileId); + } + return $files[0]; } } diff --git a/lib/private/DirectEditing/Token.php b/lib/private/DirectEditing/Token.php index c991ebef9db..add6f5b471c 100644 --- a/lib/private/DirectEditing/Token.php +++ b/lib/private/DirectEditing/Token.php @@ -50,7 +50,7 @@ class Token implements IToken { if ($this->data['share_id'] !== null) { return $this->manager->getShareForToken($this->data['share_id']); } - return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id']); + return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id'], $this->data['file_path']); } public function getToken(): string { diff --git a/lib/public/DirectEditing/IToken.php b/lib/public/DirectEditing/IToken.php index bdde5bbe949..416b2ccb807 100644 --- a/lib/public/DirectEditing/IToken.php +++ b/lib/public/DirectEditing/IToken.php @@ -25,6 +25,7 @@ namespace OCP\DirectEditing; use OCP\Files\File; +use OCP\Files\NotFoundException; /** * @since 18.0.0 @@ -65,6 +66,7 @@ interface IToken { * * @since 18.0.0 * @return File + * @throws NotFoundException */ public function getFile(): File; |