A platform for community discussion. Free, open, simple.
FIX: Skip spam scan in after_cooked_post when last editor is staff (#37465)
Osama Sayeghdee33e95b799
diff --git a/plugins/discourse-ai/lib/ai_moderation/spam_scanner.rb b/plugins/discourse-ai/lib/ai_moderation/spam_scanner.rbindex a28ae67ce85..45a7f8267a7 100644--- a/plugins/discourse-ai/lib/ai_moderation/spam_scanner.rb+++ b/plugins/discourse-ai/lib/ai_moderation/spam_scanner.rb@@ -71,6 +71,9 @@ module DiscourseAireturn if !post.custom_fields[SHOULD_SCAN_POST_CUSTOM_FIELD]return if post.updated_at < MAX_AGE_TO_SCAN.ago+ editor = post.last_editor+ return if editor && (editor.staff? || editor.bot?)+last_scan = AiSpamLog.where(post_id: post.id).order(created_at: :desc).firstif last_scan && last_scan.created_at > EDIT_DELAY_MINUTES.minutes.agodiff --git a/plugins/discourse-ai/spec/lib/modules/ai_moderation/spam_scanner_spec.rb b/plugins/discourse-ai/spec/lib/modules/ai_moderation/spam_scanner_spec.rbindex 0600ead692d..fd39a6764ab 100644--- a/plugins/discourse-ai/spec/lib/modules/ai_moderation/spam_scanner_spec.rb+++ b/plugins/discourse-ai/spec/lib/modules/ai_moderation/spam_scanner_spec.rb@@ -243,6 +243,28 @@ RSpec.describe DiscourseAi::AiModeration::SpamScanner dodescribed_class.after_cooked_post(post)}.not_to change(Jobs::AiSpamScan.jobs, :size)end++ it "does not create a reviewable when staff edits a topic" do+ Jobs.run_immediately!++ post = nil+ DiscourseAi::Completions::Llm.with_prepared_responses(+ [{ spam: false, reason: "no spam detected" }],+ ) do+ post =+ create_post(+ user: user,+ title: "Topic to test AI spam flagging",+ raw: "Initial content that will pass initial scan.",+ )+ end++ DiscourseAi::Completions::Llm.with_prepared_responses(+ [{ spam: true, reason: "spam detected" }],+ ) { PostRevisor.new(post).revise!(moderator, title: "A completely different title") }++ expect(Reviewable.where(target: post).count).to eq(0)+ endenddescribe ".hide_post" do