Skip to content

Commit

Permalink
use admin and user setting to toggle the top-right assistant
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Aug 8, 2023
1 parent 0a4e959 commit c8a9764
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,9 @@ class BeforeTemplateRenderedListener implements IEventListener {

public function __construct(
private IUserSession $userSession,
private IConfig $config,
private IInitialState $initialStateService,
private ?string $userId,
) {
}

Expand All @@ -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');
}
}
5 changes: 4 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,7 +16,9 @@ function init() {
openAssistantForm,
}
subscribe('notifications:action:execute', handleNotification)
addAssistantMenuEntry()
if (loadState('textprocessing_assistant', 'assistant-enabled')) {
addAssistantMenuEntry()
}
}
}

Expand Down

0 comments on commit c8a9764

Please sign in to comment.