diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3e4c1064..eaa0bfcc 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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: diff --git a/lib/automation.rb b/lib/automation.rb index 06a36c9a..e43bcbc5 100644 --- a/lib/automation.rb +++ b/lib/automation.rb @@ -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", diff --git a/lib/automation/llm_triage.rb b/lib/automation/llm_triage.rb index 640e7046..20ab9ae4 100644 --- a/lib/automation/llm_triage.rb +++ b/lib/automation/llm_triage.rb @@ -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 diff --git a/spec/lib/modules/automation/llm_triage_spec.rb b/spec/lib/modules/automation/llm_triage_spec.rb index e9c9979a..bbff9e10 100644 --- a/spec/lib/modules/automation/llm_triage_spec.rb +++ b/spec/lib/modules/automation/llm_triage_spec.rb @@ -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,