Skip to content

Commit f1c7ee8

Browse files
authored
DEV: Better control what prompts can appear in post/composer (#969)
This PR updates the logic for the location map so it permits only the desired prompts through to the composer/post menu. Anything else won't be shown by default. This PR also adds relevant tests to prevent regression.
1 parent 4da033c commit f1c7ee8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/ai_helper/assistant.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@ def location_map(name)
233233
%w[post]
234234
when "illustrate_post"
235235
%w[composer]
236-
when "detect_text_locale"
237-
%w[]
238236
else
239-
%w[composer post]
237+
%w[]
240238
end
241239
end
242240

spec/lib/modules/ai_helper/assistant_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@
6060
)
6161
end
6262

63+
it "returns all prompts to be shown in the composer" do
64+
prompts = subject.available_prompts(user)
65+
filtered_prompts = prompts.select { |prompt| prompt[:location].include?("composer") }
66+
expect(filtered_prompts.length).to eq(5)
67+
expect(filtered_prompts.map { |p| p[:name] }).to contain_exactly(
68+
"translate",
69+
"generate_titles",
70+
"proofread",
71+
"markdown_table",
72+
"custom_prompt",
73+
)
74+
end
75+
76+
it "returns all prompts to be shown in the post menu" do
77+
prompts = subject.available_prompts(user)
78+
filtered_prompts = prompts.select { |prompt| prompt[:location].include?("post") }
79+
expect(filtered_prompts.length).to eq(4)
80+
expect(filtered_prompts.map { |p| p[:name] }).to contain_exactly(
81+
"translate",
82+
"explain",
83+
"proofread",
84+
"custom_prompt",
85+
)
86+
end
87+
6388
it "does not raise an error when effective_locale does not exactly match keys in LocaleSiteSetting" do
6489
SiteSetting.default_locale = "zh_CN"
6590
expect { subject.available_prompts(user) }.not_to raise_error

0 commit comments

Comments
 (0)