From ec25a027f7e20286530d7d67c7196f4406ecb560 Mon Sep 17 00:00:00 2001 From: Piotr Mrowczynski Date: Thu, 28 Mar 2019 20:08:06 -0700 Subject: [PATCH] add switch to enable features --- js/viewer/attributes.js | 4 +++- lib/AppConfig.php | 14 ++++++++++++++ lib/Controller/SettingsController.php | 1 + lib/HookHandler.php | 8 +++++--- templates/admin.php | 10 ++++++++-- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/js/viewer/attributes.js b/js/viewer/attributes.js index e628e2928..38285af9e 100644 --- a/js/viewer/attributes.js +++ b/js/viewer/attributes.js @@ -11,7 +11,9 @@ OC.Plugins.register('OC.Share.ShareItemModel', { var mimetype = model.getFileInfo().getMimeType(); var folderMimeType = 'httpd/unix-directory'; if ((odfViewer.isSupportedMimeType(mimetype) || mimetype === folderMimeType) && - OC.appConfig.richdocuments && OC.appConfig.richdocuments.defaultShareAttributes) { + OC.appConfig.richdocuments && + OC.appConfig.richdocuments.secureViewAllowed && + OC.appConfig.richdocuments.defaultShareAttributes) { /** @type OC.Share.Types.RegisteredShareAttribute **/ var secureViewCanDownload = { "scope": "permissions", diff --git a/lib/AppConfig.php b/lib/AppConfig.php index 8202de6e9..f73c930cc 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -74,4 +74,18 @@ public function getUserValue($userId, $key) { public function setUserValue($userId, $key, $value) { return $this->config->setAppValue($userId, $this->appName, $key, $value); } + + /** + * Check if app can have enterprise features enabled + * + * @return bool + */ + public function enterpriseFeaturesEnabled() { + if ($this->config->getAppValue('enterprise_key', 'license-key', null) === null && + $this->config->getSystemValue('license-key', null) === null) { + return false; + } + + return true; + } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index c083ca69d..21d15803c 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -66,6 +66,7 @@ public function adminIndex() { 'external_apps' => $this->appConfig->getAppValue('external_apps'), 'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'), 'menu_option' => $this->appConfig->getAppValue('menu_option'), + 'secure_view_allowed' => $this->appConfig->enterpriseFeaturesEnabled() ? 'true' : 'false', 'secure_view_option' => $this->appConfig->getAppValue('secure_view_option'), 'secure_view_can_download_default' => $this->appConfig->getAppValue('secure_view_can_download_default'), 'secure_view_can_print_default' => $this->appConfig->getAppValue('secure_view_can_print_default'), diff --git a/lib/HookHandler.php b/lib/HookHandler.php index e848140c2..fe4f729ed 100644 --- a/lib/HookHandler.php +++ b/lib/HookHandler.php @@ -27,12 +27,14 @@ public static function addViewerScripts() { } public static function addConfigScripts($array) { - $appConfig = new AppConfig(\OC::$server->getConfig()); + $config = \OC::$server->getConfig(); + $richdocumentsConfig = new AppConfig($config); $array['array']['oc_appconfig']['richdocuments'] = [ 'defaultShareAttributes' => [ - 'secureViewCanDownload' => $appConfig->getAppValue('secure_view_can_dowload_default'), - 'secureViewCanPrint' => $appConfig->getAppValue('secure_view_can_print_default'), + 'secureViewCanDownload' => $richdocumentsConfig->getAppValue('secure_view_can_dowload_default'), + 'secureViewCanPrint' => $richdocumentsConfig->getAppValue('secure_view_can_print_default'), ], + 'secureViewAllowed' => $richdocumentsConfig->enterpriseFeaturesEnabled() ]; } } diff --git a/templates/admin.php b/templates/admin.php index cd34dde30..cc7e81c9b 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -67,8 +67,14 @@
- /> - + '); +} elseif ($_['secure_view_allowed'] !== 'true') { + p('disabled />'); +} else { + p(' />'); +}?> +