Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 2fb691c

Browse files
authored
FEATURE: Triage can hide posts after adding them to the review queue (#1348)
1 parent de06255 commit 2fb691c

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

config/locales/server.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ en:
33
ai:
44
flag_types:
55
review: "Add post to review queue"
6+
review_hide: "Add post to review queue and hide post"
67
spam: "Flag as spam and hide post"
78
spam_silence: "Flag as spam, hide post and silence user"
89
scriptables:

lib/automation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module Automation
55
def self.flag_types
66
[
77
{ id: "review", translated_name: I18n.t("discourse_automation.ai.flag_types.review") },
8+
{
9+
id: "review_hide",
10+
translated_name: I18n.t("discourse_automation.ai.flag_types.review_hide"),
11+
},
812
{ id: "spam", translated_name: I18n.t("discourse_automation.ai.flag_types.spam") },
913
{
1014
id: "spam_silence",

lib/automation/llm_triage.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def self.handle(
148148
reason: score_reason,
149149
force_review: true,
150150
)
151+
152+
# We cannot do this through the PostActionCreator because hiding a post is reserved for auto action flags.
153+
# Those flags are off_topic, inappropiate, and spam. We want a more generic type for triage, so none of those
154+
# fit here.
155+
post.hide!(PostActionType.types[:notify_moderators]) if flag_type == :review_hide
151156
end
152157
end
153158
end

spec/lib/modules/automation/llm_triage_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ def triage(**args)
128128
expect(post.user.silenced?).to eq(true)
129129
end
130130

131+
it "can handle flag + hide" do
132+
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
133+
triage(
134+
post: post,
135+
model: "custom:#{llm_model.id}",
136+
system_prompt: "test %%POST%%",
137+
search_for_text: "bad",
138+
flag_post: true,
139+
flag_type: :review_hide,
140+
automation: nil,
141+
)
142+
end
143+
144+
reviewable = ReviewablePost.last
145+
146+
expect(reviewable.target).to eq(post)
147+
expect(reviewable.reviewable_scores.first.reason).to include("bad")
148+
expect(post.reload).to be_hidden
149+
end
150+
131151
it "does not silence the user if the flag fails" do
132152
Fabricate(
133153
:post_action,

0 commit comments

Comments
 (0)