Skip to content

Commit 98f45ea

Browse files
committed
fix: Use proper file id for direct editing
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent 4ab6da5 commit 98f45ea

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

lib/Controller/DirectViewController.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\AppFramework\Http\JSONResponse;
2020
use OCP\AppFramework\Http\RedirectResponse;
2121
use OCP\AppFramework\Http\TemplateResponse;
22+
use OCP\Files\File;
2223
use OCP\Files\Folder;
2324
use OCP\Files\IRootFolder;
2425
use OCP\Files\Node;
@@ -80,7 +81,7 @@ public function show($token) {
8081

8182
try {
8283
$item = $folder->getFirstNodeById($direct->getFileid());
83-
if (!($item instanceof Node)) {
84+
if (!($item instanceof File)) {
8485
throw new \Exception();
8586
}
8687

@@ -92,8 +93,17 @@ public function show($token) {
9293
return $response;
9394
}
9495

95-
$urlSrc = $this->tokenManager->getUrlSrc($item);
96-
$wopi = $this->tokenManager->generateWopiToken($item->getId(), null, $direct->getUid(), true);
96+
$wopi = null;
97+
$template = $direct->getTemplateId() ? $this->templateManager->getTemplateSource($direct->getTemplateId()) : null;
98+
99+
if ($template !== null) {
100+
$wopi = $this->tokenManager->generateWopiTokenForTemplate($template, $direct->getUid(), $item->getId(), true);
101+
}
102+
103+
if ($wopi === null) {
104+
$urlSrc = $this->tokenManager->getUrlSrc($item);
105+
$wopi = $this->tokenManager->generateWopiToken($item->getId(), null, $direct->getUid(), true);
106+
}
97107
} catch (\Exception $e) {
98108
$this->logger->error('Failed to generate token for existing file on direct editing', ['exception' => $e]);
99109
return $this->renderErrorPage('Failed to open the requested file.');

lib/Controller/OCSController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function createFromTemplate($path, $template) {
278278
$name = $folder->getNonExistingName($info['basename']);
279279
$file = $folder->newFile($name);
280280

281-
$direct = $this->directMapper->newDirect($this->userId, $template, $file->getId());
281+
$direct = $this->directMapper->newDirect($this->userId, $file->getId(), $template);
282282

283283
return new DataResponse([
284284
'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [

lib/Db/DirectMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public function __construct(
3131
* @param int $destination
3232
* @return Direct
3333
*/
34-
public function newDirect($uid, $fileid, $destination = null, $share = null, $initiatorHost = null, $initiatorToken = null) {
34+
public function newDirect($uid, $fileid, $template = null, $share = null, $initiatorHost = null, $initiatorToken = null) {
3535
$direct = new Direct();
3636
$direct->setUid($uid);
3737
$direct->setFileid($fileid);
3838
$direct->setToken($this->random->generate(64, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER));
3939
$direct->setTimestamp($this->timeFactory->getTime());
40-
$direct->setTemplateDestination($destination);
40+
$direct->setTemplateId($template);
4141
$direct->setShare($share);
4242
$direct->setInitiatorHost($initiatorHost);
4343
$direct->setInitiatorToken($initiatorToken);

0 commit comments

Comments
 (0)