Skip to content

Commit

Permalink
fix: Bring back federated editing with new viewer iframe
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <jus@bitgrid.net>

chore: Move to route attributes

Signed-off-by: Julius Härtl <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Aug 20, 2024
1 parent 3a67f4e commit b649ea4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// Page rendering of documents
['name' => 'document#index', 'url' => 'index', 'verb' => 'GET'],
['name' => 'document#remote', 'url' => 'remote', 'verb' => 'GET'],
['name' => 'document#remotePost', 'url' => 'remote', 'verb' => 'POST'],
['name' => 'document#createFromTemplate', 'url' => 'indexTemplate', 'verb' => 'GET'],
['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'],
['name' => 'document#token', 'url' => '/token', 'verb' => 'POST'],
Expand Down
21 changes: 20 additions & 1 deletion lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ public function remote(string $shareToken, string $remoteServer, string $remoteS
'userId' => $remoteWopi->getEditorUid() ? ($remoteWopi->getEditorUid() . '@' . $remoteServer) : null,
];

return $this->documentTemplateResponse($wopi, $params);
$response = $this->documentTemplateResponse($wopi, $params);
$response->addHeader('X-Frame-Options', 'ALLOW');
return $response;
}
} catch (ShareNotFound $e) {
return new TemplateResponse('core', '404', [], 'guest');
Expand All @@ -294,6 +296,16 @@ public function remote(string $shareToken, string $remoteServer, string $remoteS
return new TemplateResponse('core', '403', [], 'guest');
}

/**
* Open file on Source instance with token from Initiator instance
*/
#[PublicPage]
#[NoCSRFRequired]
public function remotePost(string $shareToken, string $remoteServer, string $remoteServerToken, ?string $filePath = null): TemplateResponse {
return $this->remote($shareToken, $remoteServer, $remoteServerToken, $filePath);
}


private function renderErrorPage(string $message, int $status = Http::STATUS_INTERNAL_SERVER_ERROR): TemplateResponse {
$params = [
'errors' => [['error' => $message]]
Expand Down Expand Up @@ -375,6 +387,13 @@ public function token(int $fileId, ?string $shareToken = null, ?string $path = n
$share = $shareToken ? $this->shareManager->getShareByToken($shareToken) : null;
$file = $shareToken ? $this->getFileForShare($share, $fileId, $path) : $this->getFileForUser($fileId, $path);

$federatedUrl = $this->federationService->getRemoteRedirectURL($file);
if ($federatedUrl) {
return new DataResponse([
'federatedUrl' => $federatedUrl,
]);
}

$wopi = $this->getToken($file, $share);

$this->tokenManager->setGuestName($wopi, $guestName);
Expand Down
2 changes: 2 additions & 0 deletions lib/Service/FederationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public function getRemoteRedirectURL(File $item, ?Direct $direct = null, ?IShare
return null;
}


$remote = $item->getStorage()->getRemote();
$remoteCollabora = $this->getRemoteCollaboraURL($remote);
if ($remoteCollabora !== '') {
Expand All @@ -214,6 +215,7 @@ public function getRemoteRedirectURL(File $item, ?Direct $direct = null, ?IShare
$this->tokenManager->extendWithInitiatorUserToken($wopi, $direct->getInitiatorHost(), $direct->getInitiatorToken());
}


$url = rtrim($remote, '/') . '/index.php/apps/richdocuments/remote?shareToken=' . $item->getStorage()->getToken() .
'&remoteServer=' . $initiatorServer .
'&remoteServerToken=' . $initiatorToken;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/coolParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getUIDefaults = () => {
const uiMode = defaults.UIMode ?? 'notebookbar'

const systemDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
const dataset = (document.body.dataset.themes ? document.body.dataset : parent?.document.body.dataset) ?? {}
const dataset = {} // (document.body.dataset.themes ? document.body.dataset : parent?.document.body.dataset) ?? {}
const nextcloudDarkMode = dataset?.themeDark === '' || dataset?.themeDarkHighcontrast === ''
const matchedDarkMode = (!dataset?.themes || dataset?.themes === '' || dataset?.themeDefault === '') ? systemDarkMode : nextcloudDarkMode
const uiTheme = matchedDarkMode ? 'dark' : 'light'
Expand Down
8 changes: 8 additions & 0 deletions src/view/Office.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ export default {
const { data } = await axios.post(generateUrl('/apps/richdocuments/token'), {
fileId: fileid, shareToken: this.shareToken, version, guestName: getGuestNickname(),
})
if (data.federatedUrl) {
this.$set(this.formData, 'action', data.federatedUrl)
this.$nextTick(() => this.$refs.form.submit())
this.loading = LOADING_STATE.DOCUMENT_READY
return
}
Config.update('urlsrc', data.urlSrc)
Config.update('wopi_callback_url', loadState('richdocuments', 'wopi_callback_url', ''))
Expand Down

0 comments on commit b649ea4

Please sign in to comment.