2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-10-03 17:21:20 +08:00

FIX: Use persona's allowed groups for AI helper's custom prompts access (#35150)

This commit is contained in:
Roman Rizzi 2025-10-02 13:40:52 -03:00 committed by GitHub
parent 4d03447450
commit 1537f2caab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 3 deletions

View file

@ -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"

View file

@ -16,7 +16,15 @@ module DiscourseAi
end

plugin.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)
end

plugin.on(:chat_message_created) do |message, channel, user, extra|

View file

@ -5,10 +5,15 @@ RSpec.describe "AI Composer helper", type: :system do
fab!(: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 do
enable_current_plugin
Group.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.id
SiteSetting.ai_helper_enabled = true
Jobs.run_immediately!
sign_in(user)
@ -116,7 +121,7 @@ RSpec.describe "AI Composer helper", type: :system do

context "when not a member of custom prompt group" do
let(: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" do
trigger_composer_helper(input)