From 47bd0e94ec1610731ffaadfc795af77ceb6f032e Mon Sep 17 00:00:00 2001 From: Benedikt Kulmann Date: Thu, 8 Jul 2021 17:18:44 +0200 Subject: [PATCH] Fix document server loading for richdocuments and onlyoffice --- .../lib/Controller/FilesController.php | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/packages/web-integration-oc10/lib/Controller/FilesController.php b/packages/web-integration-oc10/lib/Controller/FilesController.php index a35a8b66ca6..b5024917266 100644 --- a/packages/web-integration-oc10/lib/Controller/FilesController.php +++ b/packages/web-integration-oc10/lib/Controller/FilesController.php @@ -23,6 +23,7 @@ use GuzzleHttp\Mimetypes; use OC\AppFramework\Http; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\DataDisplayResponse; @@ -42,17 +43,23 @@ class FilesController extends Controller { * @var IConfig */ private $config; + /** + * @var IAppManager + */ + private $appManager; - /** - * FilesController constructor. - * - * @param string $appName - * @param IRequest $request - * @param IConfig $config - */ - public function __construct(string $appName, IRequest $request, IConfig $config) { + /** + * FilesController constructor. + * + * @param string $appName + * @param IRequest $request + * @param IConfig $config + * @param IAppManager $appManager + */ + public function __construct(string $appName, IRequest $request, IConfig $config, IAppManager $appManager) { parent::__construct($appName, $request); $this->config = $config; + $this->appManager = $appManager; } /** @@ -144,8 +151,12 @@ private function applyCSPOnlyOffice(ContentSecurityPolicy $csp): ContentSecurity * Extracts the onlyoffice document server URL from the app * * @return string + * @throws \OCP\AppFramework\QueryException */ private function getOnlyOfficeDocumentServerUrl(): string { + if (!$this->isAppEnabled("onlyoffice")) { + return ""; + } if (!class_exists("\OCA\Onlyoffice\AppConfig")) { return ""; } @@ -171,10 +182,16 @@ private function applyCSPRichDocuments(ContentSecurityPolicy $csp): ContentSecur * @throws \OCP\AppFramework\QueryException */ private function getRichDocumentsServerUrl(): string { + if (!$this->isAppEnabled("richdocuments")) { + return ""; + } if (!class_exists("\OCA\Richdocuments\AppConfig")) { return ""; } $richdocumentsConfig = \OC::$server->query(\OCA\Richdocuments\AppConfig::class); + if (empty($richdocumentsConfig)) { + return ""; + } return $richdocumentsConfig->getAppValue('wopi_url'); } @@ -193,4 +210,17 @@ private function extractDomain(string $url): string { . $parsedUrl['host'] . (isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : ''); } + + /** + * Checks whether the given app is installed and enabled. + * + * @param string $appName + * @return bool + */ + private function isAppEnabled(string $appName): bool { + if (!$this->appManager->isInstalled($appName)) { + return false; + } + return $this->appManager->isEnabledForUser($appName); + } }