From 4395e4d165b45a40cc9ba38c1369f6934781c2c2 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Wed, 19 Aug 2020 17:31:40 -0600 Subject: [PATCH] FIX: Sending a PM through a flag on a deleted post Because we allow all the other flag types on a deleted post we should be able to send a pm to the user letting them know why we deleted their post. Bug report: https://meta.discourse.org/t/-/161156 --- lib/guardian/post_guardian.rb | 2 +- spec/components/guardian_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index d02efa61faa..7126e669122 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -33,7 +33,7 @@ module PostGuardian return false if action_key == :notify_user && (post.user.blank? || (!is_staff? && opts[:is_warning].present? && opts[:is_warning] == 'true')) taken = opts[:taken_actions].try(:keys).to_a - is_flag = PostActionType.notify_flag_types[action_key] + is_flag = PostActionType.notify_flag_types[action_key] || PostActionType.custom_types[action_key] already_taken_this_action = taken.any? && taken.include?(PostActionType.types[action_key]) already_did_flagging = taken.any? && (taken & PostActionType.notify_flag_types.values).any? diff --git a/spec/components/guardian_spec.rb b/spec/components/guardian_spec.rb index 59dd96aa900..43bf1a0ba95 100644 --- a/spec/components/guardian_spec.rb +++ b/spec/components/guardian_spec.rb @@ -112,6 +112,8 @@ describe Guardian do it "returns false when the post is deleted" do post.deleted_at = Time.now expect(Guardian.new(user).post_can_act?(post, :like)).to be_falsey + expect(Guardian.new(admin).post_can_act?(post, :spam)).to be_truthy + expect(Guardian.new(admin).post_can_act?(post, :notify_user)).to be_truthy end it "works as expected for silenced users" do