From 5ab5ff47b8ec489739de70357a865462a4d6fd4c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 8 Oct 2019 11:40:00 +0200 Subject: [PATCH] Add a setting to disable files and public sharing integration Signed-off-by: Joas Schilling --- lib/Controller/FilesIntegrationController.php | 14 ++++ lib/Files/TemplateLoader.php | 7 +- lib/PublicShare/TemplateLoader.php | 13 +++- lib/Settings/Admin/GeneralSettings.php | 2 + src/views/AdminSettings/GeneralSettings.vue | 73 +++++++++++++++++-- 5 files changed, 98 insertions(+), 11 deletions(-) diff --git a/lib/Controller/FilesIntegrationController.php b/lib/Controller/FilesIntegrationController.php index 491709ef2ca..acfbda5e563 100644 --- a/lib/Controller/FilesIntegrationController.php +++ b/lib/Controller/FilesIntegrationController.php @@ -34,6 +34,7 @@ use OCP\AppFramework\OCSController; use OCP\Files\FileInfo; use OCP\Files\NotFoundException; +use OCP\IConfig; use OCP\IL10N; use OCP\IRequest; use OCP\ISession; @@ -57,6 +58,8 @@ class FilesIntegrationController extends OCSController { private $talkSession; /** @var Util */ private $util; + /** @var IConfig */ + private $config; /** @var IL10N */ private $l; @@ -69,6 +72,7 @@ public function __construct( IUserSession $userSession, TalkSession $talkSession, Util $util, + IConfig $config, IL10N $l10n ) { parent::__construct($appName, $request); @@ -78,6 +82,7 @@ public function __construct( $this->userSession = $userSession; $this->talkSession = $talkSession; $this->util = $util; + $this->config = $config; $this->l = $l10n; } @@ -112,6 +117,10 @@ public function __construct( * @throws OCSNotFoundException */ public function getRoomByFileId(string $fileId): DataResponse { + if ($this->config->getAppValue('spreed', 'conversations_files', '1') !== '1') { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + $currentUser = $this->userSession->getUser(); if (!$currentUser instanceof IUser) { throw new OCSException($this->l->t('File is not shared, or shared but not with the user'), Http::STATUS_UNAUTHORIZED); @@ -180,6 +189,11 @@ public function getRoomByFileId(string $fileId): DataResponse { * or "404 Not found" if the given share token was invalid. */ public function getRoomByShareToken(string $shareToken): DataResponse { + if ($this->config->getAppValue('spreed', 'conversations_files', '1') !== '1' || + $this->config->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + try { $share = $this->shareManager->getShareByToken($shareToken); if ($share->getPassword() !== null) { diff --git a/lib/Files/TemplateLoader.php b/lib/Files/TemplateLoader.php index a8f41d03790..83cba79a638 100644 --- a/lib/Files/TemplateLoader.php +++ b/lib/Files/TemplateLoader.php @@ -32,7 +32,7 @@ class TemplateLoader { public static function register(EventDispatcherInterface $dispatcher): void { - $dispatcher->addListener('OCA\Files::loadAdditionalScripts', function() { + $dispatcher->addListener('OCA\Files::loadAdditionalScripts', static function() { self::loadTalkSidebarForFilesApp(); }); } @@ -44,6 +44,11 @@ public static function register(EventDispatcherInterface $dispatcher): void { * Files app. */ public static function loadTalkSidebarForFilesApp(): void { + $config = \OC::$server->getConfig(); + if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1') { + return; + } + Util::addStyle('spreed', 'merged-files'); Util::addScript('spreed', 'merged-files'); } diff --git a/lib/PublicShare/TemplateLoader.php b/lib/PublicShare/TemplateLoader.php index 1d37eb7c79d..19e3a5590b5 100644 --- a/lib/PublicShare/TemplateLoader.php +++ b/lib/PublicShare/TemplateLoader.php @@ -37,10 +37,9 @@ class TemplateLoader { public static function register(EventDispatcherInterface $dispatcher): void { - $listener = function() { + $dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', static function() { self::loadTalkSidebarUi(); - }; - $dispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', $listener); + }); } /** @@ -49,7 +48,13 @@ public static function register(EventDispatcherInterface $dispatcher): void { * This method should be called when loading additional scripts for the * public share page of the server. */ - public static function loadTalkSidebarUi() { + public static function loadTalkSidebarUi(): void { + $config = \OC::$server->getConfig(); + if ($config->getAppValue('spreed', 'conversations_files', '1') !== '1' || + $config->getAppValue('spreed', 'conversations_files_public_shares', '1') !== '1') { + return; + } + Util::addStyle('spreed', 'merged-public-share'); Util::addScript('spreed', 'merged-public-share'); } diff --git a/lib/Settings/Admin/GeneralSettings.php b/lib/Settings/Admin/GeneralSettings.php index e6d2d2f2ba7..a4ff05ca88e 100644 --- a/lib/Settings/Admin/GeneralSettings.php +++ b/lib/Settings/Admin/GeneralSettings.php @@ -47,6 +47,8 @@ public function __construct(IConfig $config, */ public function getForm(): TemplateResponse { $this->initialStateService->provideInitialState('talk', 'start_calls', (int) $this->config->getAppValue('spreed', 'start_calls', '0')); + $this->initialStateService->provideInitialState('talk', 'conversations_files', (int) $this->config->getAppValue('spreed', 'conversations_files', '1')); + $this->initialStateService->provideInitialState('talk', 'conversations_files_public_shares', (int) $this->config->getAppValue('spreed', 'conversations_files_public_shares', '1')); return new TemplateResponse('spreed', 'settings/admin/general-settings', [], ''); } diff --git a/src/views/AdminSettings/GeneralSettings.vue b/src/views/AdminSettings/GeneralSettings.vue index e50d494278f..13dce9f043c 100644 --- a/src/views/AdminSettings/GeneralSettings.vue +++ b/src/views/AdminSettings/GeneralSettings.vue @@ -31,11 +31,36 @@ :options="startCallOptions" label="label" track-by="value" - @input="saveChanges" /> + :disabled="loading || loadingStartCalls" + @input="saveStartCalls" />

{{ t('spreed', 'When a call has started, everyone with access to the conversation can join the call.') }}

+ +

{{ t('spreed', 'Integration into other apps') }}

+ +

+ + +

+ +

+ + +

@@ -56,25 +81,61 @@ export default { data() { return { - loading: false, + loading: true, + loadingStartCalls: false, + loadingConversationsFiles: false, + startCallOptions, - startCalls: startCallOptions[0] + startCalls: startCallOptions[0], + + conversationsFiles: true, + conversationsFilesPublicShares: true } }, mounted() { this.loading = true this.startCalls = startCallOptions[parseInt(OCP.InitialState.loadState('talk', 'start_calls'))] + this.conversationsFiles = parseInt(OCP.InitialState.loadState('talk', 'conversations_files')) === 1 + this.conversationsFilesPublicShares = parseInt(OCP.InitialState.loadState('talk', 'conversations_files_public_shares')) === 1 this.loading = false }, methods: { - saveChanges() { - this.loading = true + saveStartCalls() { + this.loadingStartCalls = true OCP.AppConfig.setValue('spreed', 'start_calls', this.startCalls.value, { success: function() { - this.loading = false + this.loadingStartCalls = false + }.bind(this) + }) + }, + saveConversationsFiles() { + this.loadingConversationsFiles = true + + OCP.AppConfig.setValue('spreed', 'conversations_files', this.conversationsFiles ? '1' : '0', { + success: function() { + if (!this.conversationsFiles) { + // When the file integration is disabled, the share integration is also disabled + OCP.AppConfig.setValue('spreed', 'conversations_files_public_shares', '0', { + success: function() { + this.conversationsFilesPublicShares = false + this.loadingConversationsFiles = false + }.bind(this) + }) + } else { + this.loadingConversationsFiles = false + } + }.bind(this) + }) + }, + saveConversationsFilesPublicShares() { + this.loadingConversationsFiles = true + + OCP.AppConfig.setValue('spreed', 'conversations_files_public_shares', this.conversationsFilesPublicShares ? '1' : '0', { + success: function() { + this.loadingConversationsFiles = false }.bind(this) }) }