From c8a9764e3c0a43d8c5cff7c5877548a774ba0b3c Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Tue, 8 Aug 2023 13:28:42 +0200 Subject: [PATCH] use admin and user setting to toggle the top-right assistant Signed-off-by: Julien Veyssier --- lib/Listener/BeforeTemplateRenderedListener.php | 9 +++++++++ src/main.js | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index a92f92ec..6cebcf44 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -7,8 +7,10 @@ use OCA\TPAssistant\AppInfo\Application; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\IConfig; use OCP\IUser; use OCP\IUserSession; use OCP\Util; @@ -17,6 +19,9 @@ class BeforeTemplateRenderedListener implements IEventListener { public function __construct( private IUserSession $userSession, + private IConfig $config, + private IInitialState $initialStateService, + private ?string $userId, ) { } @@ -34,6 +39,10 @@ public function handle(Event $event): void { return; } + $adminAssistantEnabled = $this->config->getAppValue(Application::APP_ID, 'assistant_enabled', '1') === '1'; + $userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1'; + $assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled; + $this->initialStateService->provideInitialState('assistant-enabled', $assistantEnabled); Util::addScript(Application::APP_ID, Application::APP_ID . '-main'); } } diff --git a/src/main.js b/src/main.js index 02ffaf7c..579db03b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,5 +1,6 @@ import { handleNotification, addAssistantMenuEntry, openAssistantForm } from './assistant.js' import { subscribe } from '@nextcloud/event-bus' +import { loadState } from '@nextcloud/initial-state' /** * - Expose OCA.TPAssistant.openTextProcessingModal to let apps use the assistant @@ -15,7 +16,9 @@ function init() { openAssistantForm, } subscribe('notifications:action:execute', handleNotification) - addAssistantMenuEntry() + if (loadState('textprocessing_assistant', 'assistant-enabled')) { + addAssistantMenuEntry() + } } }