From 2347ff707455e6da6447f12f3715a3bded408cc0 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 7 May 2024 00:43:30 +0200 Subject: [PATCH] FIX: only show discourse-ai CTA to admins (#26895) --- .../components/chat/modal/thread-settings.gjs | 25 ++++++++------- .../components/thread-settings-test.gjs | 32 +++++++++++++++++++ 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 plugins/chat/test/javascripts/components/thread-settings-test.gjs diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.gjs index a4cb248c097..6b4b27c374f 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/thread-settings.gjs @@ -12,6 +12,7 @@ import i18n from "discourse-common/helpers/i18n"; export default class ChatModalThreadSettings extends Component { @service chatApi; + @service currentUser; @tracked editedTitle = this.thread.title || ""; @tracked saving = false; @@ -74,17 +75,19 @@ export default class ChatModalThreadSettings extends Component { {{this.threadTitleLength}}/50 -
-

{{icon "info-circle"}} - {{i18n "chat.thread_title_modal.discourse_ai.title"}}

-

{{htmlSafe - (i18n - "chat.thread_title_modal.discourse_ai.description" - url="Discourse AI" - ) - }} -

-
+ {{#if this.currentUser.admin}} +
+

{{icon "info-circle"}} + {{i18n "chat.thread_title_modal.discourse_ai.title"}}

+

{{htmlSafe + (i18n + "chat.thread_title_modal.discourse_ai.description" + url="Discourse AI" + ) + }} +

+
+ {{/if}} <:footer> ", function (hooks) { + setupRenderingTest(hooks); + + test("discourse-ai - admin", async function (assert) { + this.currentUser.admin = true; + const thread = new ChatFabricators(getOwner(this)).thread(); + + await render(); + + assert.dom(".discourse-ai-cta").exists(); + }); + + test("discourse-ai - not admin", async function (assert) { + this.currentUser.admin = false; + const thread = new ChatFabricators(getOwner(this)).thread(); + + await render(); + + assert.dom(".discourse-ai-cta").doesNotExist(); + }); +});