FIX: keep track of silence reason when spam detection flags user (#1046)
Previously reason was blank for silencing user
This commit is contained in:
parent
b480f13a0f
commit
f9f89adac5
|
@ -253,6 +253,7 @@ en:
|
|||
conversation_deleted: "Conversation share deleted successfully"
|
||||
spam_detection:
|
||||
flag_reason: "Flagged as spam by <a href='%{url}'>Discourse AI</a>"
|
||||
silence_reason: "User silenced automatically by <a href='%{url}'>Discourse AI</a>"
|
||||
ai_bot:
|
||||
reply_error: "Sorry, it looks like our system encountered an unexpected issue while trying to reply.\n\n[details='Error details']\n%{details}\n[/details]"
|
||||
default_pm_prefix: "[Untitled AI bot PM]"
|
||||
|
|
|
@ -337,6 +337,8 @@ module DiscourseAi
|
|||
url = "#{Discourse.base_url}/admin/plugins/discourse-ai/ai-spam"
|
||||
reason = I18n.t("discourse_ai.spam_detection.flag_reason", url: url)
|
||||
|
||||
flagging_user = self.flagging_user
|
||||
|
||||
result =
|
||||
PostActionCreator.new(
|
||||
flagging_user,
|
||||
|
@ -347,9 +349,20 @@ module DiscourseAi
|
|||
).perform
|
||||
|
||||
log.update!(reviewable: result.reviewable)
|
||||
SpamRule::AutoSilence.new(post.user, post).silence_user
|
||||
# this is required cause tl1 is not auto hidden
|
||||
# we want to also handle tl1
|
||||
|
||||
reason = I18n.t("discourse_ai.spam_detection.silence_reason", url: url)
|
||||
silencer =
|
||||
UserSilencer.new(
|
||||
post.user,
|
||||
flagging_user,
|
||||
message: :too_many_spam_flags,
|
||||
post_id: post.id,
|
||||
reason: reason,
|
||||
keep_posts: true,
|
||||
)
|
||||
silencer.silence
|
||||
|
||||
# silencer will not hide tl1 posts, so we do this here
|
||||
hide_posts_and_topics(post.user)
|
||||
end
|
||||
|
||||
|
|
|
@ -215,6 +215,15 @@ RSpec.describe DiscourseAi::AiModeration::SpamScanner do
|
|||
expect(post.user.reload.silenced_till).to be_present
|
||||
expect(post.topic.reload.visible).to eq(false)
|
||||
|
||||
history = UserHistory.where(action: UserHistory.actions[:silence_user]).order(:id).last
|
||||
|
||||
url = "#{Discourse.base_url}/admin/plugins/discourse-ai/ai-spam"
|
||||
|
||||
expect(history.target_user_id).to eq(post.user_id)
|
||||
expect(history.details).to include(
|
||||
I18n.t("discourse_ai.spam_detection.silence_reason", url: url),
|
||||
)
|
||||
|
||||
expect(log.reviewable).to be_present
|
||||
expect(log.reviewable.created_by_id).to eq(described_class.flagging_user.id)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue