FEATURE: Triage can hide posts after adding them to the review queue (#1348)

This commit is contained in:
Roman Rizzi 2025-05-19 19:19:00 -03:00 committed by GitHub
parent de0625571b
commit 2fb691cba8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 0 deletions

View File

@ -3,6 +3,7 @@ en:
ai:
flag_types:
review: "Add post to review queue"
review_hide: "Add post to review queue and hide post"
spam: "Flag as spam and hide post"
spam_silence: "Flag as spam, hide post and silence user"
scriptables:

View File

@ -5,6 +5,10 @@ module DiscourseAi
def self.flag_types
[
{ id: "review", translated_name: I18n.t("discourse_automation.ai.flag_types.review") },
{
id: "review_hide",
translated_name: I18n.t("discourse_automation.ai.flag_types.review_hide"),
},
{ id: "spam", translated_name: I18n.t("discourse_automation.ai.flag_types.spam") },
{
id: "spam_silence",

View File

@ -148,6 +148,11 @@ module DiscourseAi
reason: score_reason,
force_review: true,
)
# We cannot do this through the PostActionCreator because hiding a post is reserved for auto action flags.
# Those flags are off_topic, inappropiate, and spam. We want a more generic type for triage, so none of those
# fit here.
post.hide!(PostActionType.types[:notify_moderators]) if flag_type == :review_hide
end
end
end

View File

@ -128,6 +128,26 @@ describe DiscourseAi::Automation::LlmTriage do
expect(post.user.silenced?).to eq(true)
end
it "can handle flag + hide" do
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
triage(
post: post,
model: "custom:#{llm_model.id}",
system_prompt: "test %%POST%%",
search_for_text: "bad",
flag_post: true,
flag_type: :review_hide,
automation: nil,
)
end
reviewable = ReviewablePost.last
expect(reviewable.target).to eq(post)
expect(reviewable.reviewable_scores.first.reason).to include("bad")
expect(post.reload).to be_hidden
end
it "does not silence the user if the flag fails" do
Fabricate(
:post_action,