Skip to content
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

fix: Use wopi callback url for all urls handed over to Collabora #3580

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ public function checkFileInfo($fileId, $access_token) {
$response['UserPrivateInfo']['ZoteroAPIKey'] = $zoteroAPIKey;
}
if ($wopi->hasTemplateId()) {
$templateUrl = 'index.php/apps/richdocuments/wopi/template/' . $wopi->getTemplateId() . '?access_token=' . $wopi->getToken();
$templateUrl = $this->urlGenerator->getAbsoluteURL($templateUrl);
$response['TemplateSource'] = $templateUrl;
$response['TemplateSource'] = $this->getWopiUrlForTemplate($wopi);
} elseif ($wopi->isTemplateToken()) {
// FIXME: Remove backward compatibility layer once TemplateSource is available in all supported Collabora versions
$userFolder = $this->rootFolder->getUserFolder($wopi->getOwnerUid());
Expand Down Expand Up @@ -283,7 +281,7 @@ private function setFederationFileInfo(Wopi $wopi, $response) {
$response['TemplateSource'] = $templateUrl;
}
if ($wopi->getTokenType() === Wopi::TOKEN_TYPE_REMOTE_USER || ($wopi->getTokenType() === Wopi::TOKEN_TYPE_REMOTE_GUEST && $initiator->getEditorUid())) {
$response['UserExtraInfo']['avatar'] = $wopi->getRemoteServer() . '/index.php/avatar/' . $initiator->getEditorUid() . '/'. self::WOPI_AVATAR_SIZE;
$response['UserExtraInfo']['avatar'] = $wopi->getRemoteServer() . '/index.php/avatar/' . $initiator->getEditorUid() . '/' . self::WOPI_AVATAR_SIZE;
}

return $response;
Expand Down Expand Up @@ -497,11 +495,7 @@ public function putFile($fileId,
if ($isPutRelative) {
// generate a token for the new file (the user still has to be logged in)
$wopi = $this->tokenManager->generateWopiToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect());

$wopiUrl = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
$wopiUrl = $this->urlGenerator->getAbsoluteURL($wopiUrl);

return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $wopiUrl ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName(), 'Url' => $this->getWopiUrlForFile($wopi, $file)], Http::STATUS_OK);
}
if ($wopi->hasTemplateId()) {
$wopi->setTemplateId(null);
Expand Down Expand Up @@ -665,17 +659,14 @@ public function postFile(string $fileId, string $access_token): JSONResponse {

// epub is exception (can be uploaded but not opened so don't try to get access token)
if ($file->getMimeType() == 'application/epub+zip') {
return new JSONResponse([ 'Name' => $file->getName() ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName()], Http::STATUS_OK);
}

// generate a token for the new file (the user still has to be
// logged in)
$wopi = $this->tokenManager->generateWopiToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect());

$wopiUrl = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
$wopiUrl = $this->urlGenerator->getAbsoluteURL($wopiUrl);

return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $wopiUrl ], Http::STATUS_OK);
return new JSONResponse(['Name' => $file->getName(), 'Url' => $this->getWopiUrlForFile($wopi, $file)], Http::STATUS_OK);
} catch (NotFoundException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
return new JSONResponse([], Http::STATUS_NOT_FOUND);
Expand Down Expand Up @@ -706,6 +697,7 @@ private function lock(Wopi $wopi, string $lock): JSONResponse {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

private function unlock(Wopi $wopi, string $lock): JSONResponse {
try {
$this->lockManager->unlock(new LockContext(
Expand Down Expand Up @@ -889,4 +881,14 @@ private function isMasterKeyEnabled(): bool {
return false;
}
}

private function getWopiUrlForFile(Wopi $wopi, File $file): string {
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
return $nextcloudUrl . '/index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken();
}

private function getWopiUrlForTemplate(Wopi $wopi): string {
$nextcloudUrl = $this->appConfig->getNextcloudUrl() ?: trim($this->urlGenerator->getAbsoluteURL(''), '/');
return $nextcloudUrl . '/index.php/apps/richdocuments/wopi/template/' . $wopi->getTemplateId() . '?access_token=' . $wopi->getToken();
}
}
2 changes: 1 addition & 1 deletion src/helpers/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getCallbackBaseUrl = () => {
}

const getWopiSrc = (fileId) => {
// WOPISrc - URL that loolwsd will access (ie. pointing to ownCloud)
// WOPISrc - URL that Collabora will use to access Nextcloud
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blizzz Sneaked this in from your comment in #3575 😁

// index.php is forced here to avoid different wopi srcs for the same document
const wopiurl = getCallbackBaseUrl() + '/index.php/apps/richdocuments/wopi/files/' + fileId
console.debug('[getWopiUrl] ' + wopiurl)
Expand Down
Loading