FIX: Don't notify of post deletion when agreeing with automatic flags. (#19241)
This commit is contained in:
parent
aab4ea1849
commit
88a0384d43
|
@ -330,6 +330,12 @@ class PostDestroyer
|
|||
allowed_user = @user.human? && @user.staff?
|
||||
return unless allowed_user && rs = reviewable.reviewable_scores.order('created_at DESC').first
|
||||
|
||||
# ReviewableScore#types is a superset of PostActionType#flag_types.
|
||||
# If the reviewable score type is not on the latter, it means it's not a flag by a user and
|
||||
# must be an automated flag like `needs_approval`. There's no flag reason for these kind of types.
|
||||
flag_type = PostActionType.flag_types[rs.reviewable_score_type]
|
||||
return unless flag_type
|
||||
|
||||
notify_responders = options[:notify_responders]
|
||||
|
||||
Jobs.enqueue(
|
||||
|
@ -341,7 +347,7 @@ class PostDestroyer
|
|||
flagged_post_response_raw_content: @post.raw,
|
||||
url: notify_responders ? options[:parent_post].url : @post.url,
|
||||
flag_reason: I18n.t(
|
||||
"flag_reasons#{".responder" if notify_responders}.#{PostActionType.types[rs.reviewable_score_type]}",
|
||||
"flag_reasons#{".responder" if notify_responders}.#{flag_type}",
|
||||
locale: SiteSetting.default_locale,
|
||||
base_path: Discourse.base_path
|
||||
)
|
||||
|
|
|
@ -322,6 +322,14 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
|||
expect(Jobs::SendSystemMessage.jobs.last["args"].first["message_type"]).to eq("flags_agreed_and_post_deleted_for_responders")
|
||||
end
|
||||
|
||||
it "skips responders notification when the score type doesn't match any post action flag type" do
|
||||
flagged_post.reviewable_scores.first.update!(reviewable_score_type: ReviewableScore.types[:needs_approval])
|
||||
|
||||
expect {
|
||||
flagged_post.perform(moderator, :delete_and_agree_replies)
|
||||
}.not_to change(Jobs::SendSystemMessage.jobs, :size)
|
||||
end
|
||||
|
||||
it "ignores flagged responses" do
|
||||
SiteSetting.notify_users_after_responses_deleted_on_flagged_post = true
|
||||
flagged_reply = Fabricate(:reviewable_flagged_post, target: reply)
|
||||
|
@ -361,9 +369,9 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
|||
|
||||
def assert_pm_creation_enqueued(user_id, pm_type)
|
||||
expect(Jobs::SendSystemMessage.jobs.length).to eq(1)
|
||||
job = Jobs::SendSystemMessage.jobs[0]
|
||||
expect(job["args"][0]["user_id"]).to eq(user_id)
|
||||
expect(job["args"][0]["message_type"]).to eq(pm_type)
|
||||
job = Jobs::SendSystemMessage.jobs[0]
|
||||
expect(job["args"][0]["user_id"]).to eq(user_id)
|
||||
expect(job["args"][0]["message_type"]).to eq(pm_type)
|
||||
end
|
||||
|
||||
def create_reply(post)
|
||||
|
|
Loading…
Reference in New Issue