mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-06-26 17:42:15 +00:00
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"
|
conversation_deleted: "Conversation share deleted successfully"
|
||||||
spam_detection:
|
spam_detection:
|
||||||
flag_reason: "Flagged as spam by <a href='%{url}'>Discourse AI</a>"
|
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:
|
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]"
|
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]"
|
default_pm_prefix: "[Untitled AI bot PM]"
|
||||||
|
@ -337,6 +337,8 @@ module DiscourseAi
|
|||||||
url = "#{Discourse.base_url}/admin/plugins/discourse-ai/ai-spam"
|
url = "#{Discourse.base_url}/admin/plugins/discourse-ai/ai-spam"
|
||||||
reason = I18n.t("discourse_ai.spam_detection.flag_reason", url: url)
|
reason = I18n.t("discourse_ai.spam_detection.flag_reason", url: url)
|
||||||
|
|
||||||
|
flagging_user = self.flagging_user
|
||||||
|
|
||||||
result =
|
result =
|
||||||
PostActionCreator.new(
|
PostActionCreator.new(
|
||||||
flagging_user,
|
flagging_user,
|
||||||
@ -347,9 +349,20 @@ module DiscourseAi
|
|||||||
).perform
|
).perform
|
||||||
|
|
||||||
log.update!(reviewable: result.reviewable)
|
log.update!(reviewable: result.reviewable)
|
||||||
SpamRule::AutoSilence.new(post.user, post).silence_user
|
|
||||||
# this is required cause tl1 is not auto hidden
|
reason = I18n.t("discourse_ai.spam_detection.silence_reason", url: url)
|
||||||
# we want to also handle tl1
|
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)
|
hide_posts_and_topics(post.user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -215,6 +215,15 @@ RSpec.describe DiscourseAi::AiModeration::SpamScanner do
|
|||||||
expect(post.user.reload.silenced_till).to be_present
|
expect(post.user.reload.silenced_till).to be_present
|
||||||
expect(post.topic.reload.visible).to eq(false)
|
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).to be_present
|
||||||
expect(log.reviewable.created_by_id).to eq(described_class.flagging_user.id)
|
expect(log.reviewable.created_by_id).to eq(described_class.flagging_user.id)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user