diff --git a/lib/Capabilities.php b/lib/Capabilities.php index 3954bebbc9..a613edea41 100644 --- a/lib/Capabilities.php +++ b/lib/Capabilities.php @@ -150,7 +150,7 @@ public function getCapabilities() { 'mimetypesSecureView' => $this->config->useSecureViewAdditionalMimes() ? self::SECURE_VIEW_ADDITIONAL_MIMES : [], 'collabora' => $collaboraCapabilities, 'direct_editing' => ($collaboraCapabilities['hasMobileSupport'] ?? false) && $this->config->getAppValue('mobile_editing', 'yes') === 'yes', - 'templates' => ($collaboraCapabilities['hasTemplateSaveAs'] ?? false) || ($collaboraCapabilities['hasTemplateSource'] ?? false), + 'templates' => ($collaboraCapabilities['hasTemplateSource'] ?? false), 'productName' => $this->capabilitiesService->getProductName(), 'editonline_endpoint' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.document.editOnline'), 'config' => [ diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index 5ca21b648a..02097675ad 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -94,48 +94,30 @@ public function show($token) { $this->userScopeService->setFilesystemScope($direct->getUid()); $folder = $this->rootFolder->getUserFolder($direct->getUid()); - if ($this->templateManager->isTemplate($direct->getFileid())) { - $item = $this->templateManager->get($direct->getFileid()); - if ($direct->getTemplateDestination() === 0 || $direct->getTemplateDestination() === null) { - return new JSONResponse([], Http::STATUS_BAD_REQUEST); - } - - try { - $urlSrc = $this->tokenManager->getUrlSrc($item); - $wopi = $this->tokenManager->generateWopiTokenForTemplate($item, $direct->getUid(), $direct->getTemplateDestination(), true); - - $targetFile = $folder->getById($direct->getTemplateDestination())[0]; - $relativePath = $folder->getRelativePath($targetFile->getPath()); - } catch (\Exception $e) { - $this->logger->error('Failed to generate token for new file on direct editing', ['exception' => $e]); - return new JSONResponse([], Http::STATUS_BAD_REQUEST); + try { + $item = $folder->getById($direct->getFileid())[0]; + if (!($item instanceof Node)) { + throw new \Exception(); } - } else { - try { - $item = $folder->getById($direct->getFileid())[0]; - if (!($item instanceof Node)) { - throw new \Exception(); - } - - /** Open file from remote collabora */ - $federatedUrl = $this->federationService->getRemoteRedirectURL($item, $direct); - if ($federatedUrl !== null) { - $response = new RedirectResponse($federatedUrl); - $response->addHeader('X-Frame-Options', 'ALLOW'); - return $response; - } - $urlSrc = $this->tokenManager->getUrlSrc($item); - $wopi = $this->tokenManager->generateWopiToken($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.'); + /** Open file from remote collabora */ + $federatedUrl = $this->federationService->getRemoteRedirectURL($item, $direct); + if ($federatedUrl !== null) { + $response = new RedirectResponse($federatedUrl); + $response->addHeader('X-Frame-Options', 'ALLOW'); + return $response; } - $relativePath = $folder->getRelativePath($item->getPath()); + $urlSrc = $this->tokenManager->getUrlSrc($item); + $wopi = $this->tokenManager->generateWopiToken($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.'); } + $relativePath = $folder->getRelativePath($item->getPath()); + try { $params = [ 'permissions' => $item->getPermissions(), diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 3f32a1a7f3..a8fd8a6d03 100644 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -121,12 +121,7 @@ public function checkFileInfo($fileId, $access_token) { [$fileId, , $version] = Helper::parseFileId($fileId); $wopi = $this->wopiMapper->getWopiForToken($access_token); - if ($wopi->isTemplateToken()) { - $this->templateManager->setUserId($wopi->getOwnerUid()); - $file = $this->templateManager->get($wopi->getFileid()); - } else { - $file = $this->getFileForWopiToken($wopi); - } + $file = $this->getFileForWopiToken($wopi); if (!($file instanceof File)) { throw new NotFoundException('No valid file found for ' . $fileId); } @@ -195,11 +190,6 @@ public function checkFileInfo($fileId, $access_token) { } if ($wopi->hasTemplateId()) { $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()); - $file = $userFolder->getById($wopi->getTemplateDestination())[0]; - $response['TemplateSaveAs'] = $file->getName(); } $share = $this->getShareForWopiToken($wopi); @@ -322,16 +312,6 @@ public function getFile($fileId, return new JSONResponse([], Http::STATUS_FORBIDDEN); } - // Template is just returned as there is no version logic - if ($wopi->isTemplateToken()) { - $this->templateManager->setUserId($wopi->getOwnerUid()); - $file = $this->templateManager->get($wopi->getFileid()); - $response = new StreamResponse($file->fopen('rb')); - $response->addHeader('Content-Disposition', 'attachment'); - $response->addHeader('Content-Type', 'application/octet-stream'); - return $response; - } - try { /** @var File $file */ $file = $this->getFileForWopiToken($wopi); @@ -579,10 +559,7 @@ public function postFile(string $fileId, string $access_token): JSONResponse { // the new file needs to be installed in the current user dir $userFolder = $this->rootFolder->getUserFolder($editor); - if ($wopi->isTemplateToken()) { - $this->templateManager->setUserId($wopi->getOwnerUid()); - $file = $userFolder->getById($wopi->getTemplateDestination())[0]; - } elseif ($isRenameFile) { + if ($isRenameFile) { // the new file needs to be installed in the current user dir $file = $this->getFileForWopiToken($wopi); diff --git a/lib/Db/Wopi.php b/lib/Db/Wopi.php index 2e14767aff..177f10038e 100644 --- a/lib/Db/Wopi.php +++ b/lib/Db/Wopi.php @@ -152,10 +152,6 @@ public function __construct() { $this->addType('tokenType', 'int'); } - public function isTemplateToken() { - return $this->getTemplateDestination() !== 0 && $this->getTemplateDestination() !== null; - } - public function hasTemplateId() { return $this->getTemplateId() !== 0 && $this->getTemplateId() !== null; } diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index 7425b22dd5..65e58b3768 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -70,7 +70,7 @@ public function __construct(IDBConnection $db, * @param int $templateDestination * @return Wopi */ - public function generateFileToken($fileId, $owner, $editor, $version, $updatable, $serverHost, $guestDisplayname = null, $templateDestination = 0, $hideDownload = false, $direct = false, $templateId = 0, $share = null) { + public function generateFileToken($fileId, $owner, $editor, $version, $updatable, $serverHost, $guestDisplayname = null, $hideDownload = false, $direct = false, $templateId = 0, $share = null) { $token = $this->random->generate(32, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS); $wopi = Wopi::fromParams([ @@ -83,7 +83,6 @@ public function generateFileToken($fileId, $owner, $editor, $version, $updatable 'token' => $token, 'expiry' => $this->calculateNewTokenExpiry(), 'guestDisplayname' => $guestDisplayname, - 'templateDestination' => $templateDestination, 'hideDownload' => $hideDownload, 'direct' => $direct, 'templateId' => $templateId, diff --git a/lib/Service/CapabilitiesService.php b/lib/Service/CapabilitiesService.php index 7bd316f5c9..6edf8aa6c9 100644 --- a/lib/Service/CapabilitiesService.php +++ b/lib/Service/CapabilitiesService.php @@ -102,10 +102,6 @@ public function hasDrawSupport(): bool { return version_compare($productVersion, '6.4.7', '>='); } - public function hasTemplateSaveAs(): bool { - return $this->getCapabilities()['hasTemplateSaveAs'] ?? false; - } - public function hasTemplateSource(): bool { return $this->getCapabilities()['hasTemplateSource'] ?? false; } diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 5b0710f5d6..74e1c424ec 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -63,7 +63,7 @@ public function getForm(): TemplateResponse { 'canonical_webroot' => $this->config->getAppValue('richdocuments', 'canonical_webroot'), 'disable_certificate_verification' => $this->config->getAppValue('richdocuments', 'disable_certificate_verification', '') === 'yes', 'templates' => $this->manager->getSystemFormatted(), - 'templatesAvailable' => $this->capabilitiesService->hasTemplateSaveAs() || $this->capabilitiesService->hasTemplateSource(), + 'templatesAvailable' => $this->capabilitiesService->hasTemplateSource(), 'settings' => $this->appConfig->getAppSettings(), 'demo_servers' => $this->demoService->fetchDemoServers(), 'web_server' => strtolower($_SERVER['SERVER_SOFTWARE']), diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php index 4109ecbc75..78e71d6c4b 100644 --- a/lib/Settings/Personal.php +++ b/lib/Settings/Personal.php @@ -51,7 +51,7 @@ public function __construct(IConfig $config, CapabilitiesService $capabilitiesSe /** @psalm-suppress InvalidNullableReturnType */ public function getForm() { - if (!$this->capabilitiesService->hasTemplateSaveAs() && !$this->capabilitiesService->hasTemplateSource()) { + if (!$this->capabilitiesService->hasTemplateSource()) { /** @psalm-suppress NullableReturnStatement */ return null; } @@ -70,7 +70,7 @@ public function getForm() { } public function getSection() { - if (!$this->capabilitiesService->hasTemplateSaveAs() && !$this->capabilitiesService->hasTemplateSource()) { + if (!$this->capabilitiesService->hasTemplateSource()) { return null; } diff --git a/lib/TokenManager.php b/lib/TokenManager.php index 04dc3dd2d1..f026bbb977 100644 --- a/lib/TokenManager.php +++ b/lib/TokenManager.php @@ -199,7 +199,7 @@ public function generateWopiToken(string $fileId, ?string $shareToken = null, ?s $serverHost = $this->urlGenerator->getAbsoluteURL('/'); $guestName = $this->userId === null ? $this->prepareGuestName($this->helper->getGuestNameFromCookie()) : null; - return $this->wopiMapper->generateFileToken($fileId, $owneruid, $editoruid, $version, $updatable, $serverHost, $guestName, 0, $hideDownload, $direct, 0, $shareToken); + return $this->wopiMapper->generateFileToken($fileId, $owneruid, $editoruid, $version, $updatable, $serverHost, $guestName, $hideDownload, $direct, 0, $shareToken); } /** @@ -255,12 +255,8 @@ public function generateWopiTokenForTemplate(File $templateFile, ?string $userId $serverHost = $this->urlGenerator->getAbsoluteURL('/'); - if ($this->capabilitiesService->hasTemplateSource()) { - return $this->wopiMapper->generateFileToken($targetFile->getId(), $owneruid, $editoruid, 0, $updatable, $serverHost, null, 0, false, $direct, $templateFile->getId()); - } - - // Legacy way of creating new documents from a template - return $this->wopiMapper->generateFileToken($templateFile->getId(), $owneruid, $editoruid, 0, $updatable, $serverHost, null, $targetFile->getId(), $direct); + return $this->wopiMapper->generateFileToken($targetFile->getId(), $owneruid, $editoruid, 0, $updatable, $serverHost, null, + false, $direct, $templateFile->getId()); } public function newInitiatorToken($sourceServer, ?Node $node = null, $shareToken = null, bool $direct = false, $userId = null): Wopi {