Skip to content

Commit

Permalink
Fix document server loading for richdocuments and onlyoffice
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jul 8, 2021
1 parent 0ca7858 commit 47bd0e9
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions packages/web-integration-oc10/lib/Controller/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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 "";
}
Expand All @@ -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');
}

Expand All @@ -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);
}
}

0 comments on commit 47bd0e9

Please sign in to comment.