diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index c35a2df237..a710928cd7 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -157,7 +157,7 @@ public function show($token) { return $response; } - list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($item->getId(), null, $direct->getUid(), true); + list($urlSrc, $wopi) = $this->tokenManager->getToken($item->getId(), null, $direct->getUid(), true); } catch (\Exception $e) { $this->logger->error('Failed to generate token for existing file on direct editing', ['exception' => $e]); return $this->renderErrorPage('Failed to open the requested file.'); @@ -218,11 +218,11 @@ public function showPublicShare(Direct $direct) { 'directGuest' => empty($direct->getUid()), ]; - list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($node->getId(), $direct->getShare(), $direct->getUid(), true); + list($urlSrc, $wopi) = $this->tokenManager->getToken($node->getId(), $direct->getShare(), $direct->getUid(), true); if (!empty($direct->getInitiatorHost())) { $this->tokenManager->upgradeFromDirectInitiator($direct, $wopi); } - $params['token'] = $token; + $params['token'] = $wopi->getToken(); $params['token_ttl'] = $wopi->getExpiry(); $params['urlsrc'] = $urlSrc; diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 5e5c65e5c7..0545075a82 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -92,11 +92,11 @@ public function extAppGetData(int $fileId): array { if (!($item instanceof Node)) { throw new Exception(); } - list($urlSrc, $token) = $this->tokenManager->getToken($item->getId()); + list($urlSrc, $wopi) = $this->tokenManager->getToken($item->getId()); return [ 'status' => 'success', 'urlsrc' => $urlSrc, - 'token' => $token + 'token' => $wopi->getToken() ]; } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); @@ -147,14 +147,14 @@ public function index($fileId, ?string $path = null) { list($urlSrc, $wopi) = $this->tokenManager->getTokenForTemplate($templateFile, $this->userId, $item->getId()); $token = $wopi->getToken(); } else { - list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($item->getId()); + list($urlSrc, $wopi) = $this->tokenManager->getToken($item->getId()); } $params = [ 'permissions' => $item->getPermissions(), 'title' => $item->getName(), 'fileId' => $item->getId() . '_' . $this->config->getSystemValue('instanceid'), - 'token' => $token, + 'token' => $wopi->getToken(), 'token_ttl' => $wopi->getExpiry(), 'urlsrc' => $urlSrc, 'path' => $folder->getRelativePath($item->getPath()), @@ -284,7 +284,7 @@ public function publicPage($shareToken, $fileName, $fileId) { if ($templateFile) { list($urlSrc, $wopi) = $this->tokenManager->getTokenForTemplate($templateFile, $share->getShareOwner(), $item->getId()); } else { - list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($item->getId(), $shareToken, $this->userId); + list($urlSrc, $wopi) = $this->tokenManager->getToken($item->getId(), $shareToken, $this->userId); } $params['token'] = $wopi->getToken(); $params['token_ttl'] = $wopi->getExpiry(); @@ -335,7 +335,7 @@ public function remote($shareToken, $remoteServer, $remoteServerToken, $filePath } if ($node instanceof Node) { - list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($node->getId(), $shareToken, $this->userId); + list($urlSrc, $wopi) = $this->tokenManager->getToken($node->getId(), $shareToken, $this->userId); $remoteWopi = $this->federationService->getRemoteFileDetails($remoteServer, $remoteServerToken); if ($remoteWopi === null) { @@ -352,7 +352,7 @@ public function remote($shareToken, $remoteServer, $remoteServerToken, $filePath 'permissions' => $permissions, 'title' => $node->getName(), 'fileId' => $node->getId() . '_' . $this->config->getSystemValue('instanceid'), - 'token' => $token, + 'token' => $wopi->getToken(), 'token_ttl' => $wopi->getExpiry(), 'urlsrc' => $urlSrc, 'path' => '/', @@ -462,7 +462,13 @@ public function editOnlineTarget(int $fileId, ?string $target = null) { #[PublicPage] public function token(int $fileId, ?string $shareToken = null): DataResponse { try { - [$urlSrc, , $wopi] = $this->tokenManager->getToken((string)$fileId, $shareToken, $this->userId); + // Get file and share + $templateFile = $this->templateManager->getTemplateSource($fileId); + if ($templateFile) { + [$urlSrc, $wopi] = $this->tokenManager->getTokenForTemplate($templateFile, $share->getShareOwner(), $item->getId()); + } else { + [$urlSrc, $wopi] = $this->tokenManager->getToken($fileId, $shareToken, $this->userId); + } return new DataResponse(array_merge( [ 'urlSrc' => $urlSrc ], diff --git a/lib/Controller/DocumentTrait.php b/lib/Controller/DocumentTrait.php index 156e2b099c..47d938cc4e 100644 --- a/lib/Controller/DocumentTrait.php +++ b/lib/Controller/DocumentTrait.php @@ -2,6 +2,7 @@ namespace OCA\Richdocuments\Controller; +use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Db\Wopi; use OCP\AppFramework\Http\FeaturePolicy; use OCP\AppFramework\Http\TemplateResponse; @@ -9,7 +10,7 @@ use OCP\EventDispatcher\IEventDispatcher; trait DocumentTrait { - private $appConfig; + private AppConfig $appConfig; private function documentTemplateResponse(Wopi $wopi, array $params): TemplateResponse { $eventDispatcher = \OC::$server->get(IEventDispatcher::class); diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 7bf0176c54..362ce32485 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -510,9 +510,9 @@ public function putFile($fileId, if ($isPutRelative) { // generate a token for the new file (the user still has to be logged in) - list(, $wopiToken) = $this->tokenManager->getToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect()); + list(, $wopi) = $this->tokenManager->getToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect()); - $wopi = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopiToken; + $wopi = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken(); $url = $this->urlGenerator->getAbsoluteURL($wopi); return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $url ], Http::STATUS_OK); @@ -684,9 +684,9 @@ public function postFile(string $fileId, string $access_token): JSONResponse { // generate a token for the new file (the user still has to be // logged in) - list(, $wopiToken) = $this->tokenManager->getToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect()); + list(, $wopi) = $this->tokenManager->getToken((string)$file->getId(), null, $wopi->getEditorUid(), $wopi->getDirect()); - $wopi = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopiToken; + $wopi = 'index.php/apps/richdocuments/wopi/files/' . $file->getId() . '_' . $this->config->getSystemValue('instanceid') . '?access_token=' . $wopi->getToken(); $url = $this->urlGenerator->getAbsoluteURL($wopi); return new JSONResponse([ 'Name' => $file->getName(), 'Url' => $url ], Http::STATUS_OK); diff --git a/lib/Service/InitialStateService.php b/lib/Service/InitialStateService.php index 1e824d3578..a9b9b7408a 100644 --- a/lib/Service/InitialStateService.php +++ b/lib/Service/InitialStateService.php @@ -67,6 +67,8 @@ public function provideCapabilities(): void { $this->initialState->provideInitialState('hasDrawSupport', $this->capabilitiesService->hasDrawSupport()); $this->initialState->provideInitialState('hasNextcloudBranding', $this->capabilitiesService->hasNextcloudBranding()); + $this->provideOptions(); + $this->hasProvidedCapabilities = true; } @@ -76,17 +78,8 @@ public function provideDocument(Wopi $wopi, array $params): void { $this->initialState->provideInitialState('document', $this->prepareParams($params)); $this->initialState->provideInitialState('wopi', $wopi); - $this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud')); - $this->initialState->provideInitialState('uiDefaults', [ - 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'notebookbar') - ]); - $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; - if (!$logoSet) { - $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; - } - $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? - \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) - : false)); + + $this->provideOptions(); } public function prepareParams(array $params): array { @@ -108,4 +101,18 @@ public function prepareParams(array $params): array { return array_merge($defaults, $params); } + + private function provideOptions(): void { + $this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud')); + $this->initialState->provideInitialState('uiDefaults', [ + 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'notebookbar') + ]); + $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; + if (!$logoSet) { + $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; + } + $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? + \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) + : false)); + } } diff --git a/lib/TokenManager.php b/lib/TokenManager.php index 91bd9f65ff..b60776bf49 100644 --- a/lib/TokenManager.php +++ b/lib/TokenManager.php @@ -207,7 +207,6 @@ public function getToken(string $fileId, $shareToken = null, $editoruid = null, return [ $this->wopiParser->getUrlSrc($file->getMimeType())['urlsrc'], // url src might not be found ehre - $wopi->getToken(), $wopi ]; } @@ -281,7 +280,7 @@ public function getTokenForTemplate(File $templateFile, $userId, $targetFileId, public function newInitiatorToken($sourceServer, Node $node = null, $shareToken = null, bool $direct = false, $userId = null): Wopi { if ($node !== null) { - list($urlSrc, $token, $wopi) = $this->getToken($node->getId(), $shareToken, $userId, $direct); + list($urlSrc, $wopi) = $this->getToken($node->getId(), $shareToken, $userId, $direct); $wopi->setServerHost($sourceServer); $wopi->setTokenType(Wopi::TOKEN_TYPE_INITIATOR); $this->wopiMapper->update($wopi);