A platform for community discussion. Free, open, simple.
FIX: Use persona's allowed groups for AI helper's custom prompts access (#35150)
Roman Rizzi1537f2caabb9
diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex a1570d3f128..da5c41abba8 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -85,7 +85,6 @@ en:composer_ai_helper_allowed_groups: "Users on these groups will see the AI helper button in the composer."ai_helper_allowed_in_pm: "Enable the composer's AI helper in PMs."ai_helper_model: "Model to use for the AI helper."- ai_helper_custom_prompts_allowed_groups: "Users on these groups will see the custom prompt option in the AI helper."ai_helper_automatic_chat_thread_title_delay: "Delay in minutes before the AI helper automatically sets the chat thread title."ai_helper_automatic_chat_thread_title: "Automatically set the chat thread titles based on thread contents."ai_helper_illustrate_post_model: "Model to use for the composer AI helper's illustrate post feature"diff --git a/plugins/discourse-ai/lib/ai_helper/entry_point.rb b/plugins/discourse-ai/lib/ai_helper/entry_point.rbindex e7b85f88763..ac240e9fe3e 100644--- a/plugins/discourse-ai/lib/ai_helper/entry_point.rb+++ b/plugins/discourse-ai/lib/ai_helper/entry_point.rb@@ -16,7 +16,15 @@ module DiscourseAiendplugin.add_to_serializer(:current_user, :can_use_custom_prompts) do- scope.user.in_any_groups?(SiteSetting.ai_helper_custom_prompts_allowed_groups_map)+ return [] if !SiteSetting.ai_helper_enabled++ custom_prompt_allowed_group_ids =+ DB.query_single(+ "SELECT allowed_group_ids FROM ai_personas WHERE id = :customp_prompt_persona_id",+ customp_prompt_persona_id: SiteSetting.ai_helper_custom_prompt_persona,+ ).flatten++ scope.user.in_any_groups?(custom_prompt_allowed_group_ids)endplugin.on(:chat_message_created) do |message, channel, user, extra|diff --git a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rbindex 173fbe6ce9e..786944165eb 100644--- a/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb+++ b/plugins/discourse-ai/spec/system/ai_helper/ai_composer_helper_spec.rb@@ -5,10 +5,15 @@ RSpec.describe "AI Composer helper", type: :system dofab!(:non_member_group) { Fabricate(:group) }fab!(:embedding_definition)+ fab!(:custom_prompts_persona) do+ Fabricate(:ai_persona, allowed_group_ids: [Group::AUTO_GROUPS[:admins]])+ end+before doenable_current_pluginGroup.find_by(id: Group::AUTO_GROUPS[:admins]).add(user)assign_fake_provider_to(:ai_default_llm_model)+ SiteSetting.ai_helper_custom_prompt_persona = custom_prompts_persona.idSiteSetting.ai_helper_enabled = trueJobs.run_immediately!sign_in(user)@@ -116,7 +121,7 @@ RSpec.describe "AI Composer helper", type: :system docontext "when not a member of custom prompt group" dolet(:mode) { DiscourseAi::AiHelper::Assistant::CUSTOM_PROMPT }- before { SiteSetting.ai_helper_custom_prompts_allowed_groups = non_member_group.id.to_s }+ before { custom_prompts_persona.update!(allowed_group_ids: [non_member_group.id]) }it "does not show custom prompt option" dotrigger_composer_helper(input)