A platform for community discussion. Free, open, simple.
FIX: don't send PM if flagged post is deleted but flags were deferred or cleared
Neil Lalonde135c803f492f
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex 7d70b8ecb73..33c316007a4 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -196,7 +196,7 @@ class PostDestroyerenddef agree_with_flags- if @post.is_flagged? && @user.id > 0 && @user.staff?+ if @post.has_active_flag? && @user.id > 0 && @user.staff?Jobs.enqueue(:send_system_message,user_id: @post.user.id,diff --git a/spec/components/post_destroyer_spec.rb b/spec/components/post_destroyer_spec.rbindex 9c81366a0d1..f1c772478f3 100644--- a/spec/components/post_destroyer_spec.rb+++ b/spec/components/post_destroyer_spec.rb@@ -606,6 +606,16 @@ describe PostDestroyer doTopic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?).to eq(false)end++ it "should not send the flags_agreed_and_post_deleted message if flags were deferred" do+ second_post.expects(:update_flagged_posts_count)+ PostAction.defer_flags!(second_post, moderator)+ second_post.reload+ PostDestroyer.new(moderator, second_post).destroy+ expect(+ Topic.where(title: I18n.t('system_messages.flags_agreed_and_post_deleted.subject_template')).exists?+ ).to eq(false)+ endenddescribe "user actions" dodiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 9ea0db26dc2..99dbfe7fb4e 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -141,7 +141,7 @@ describe Post dolet(:user) { Fabricate(:coding_horror) }let(:admin) { Fabricate(:admin) }- it 'isFlagged is accurate' do+ it 'is_flagged? is accurate' doPostAction.act(user, post, PostActionType.types[:off_topic])post.reloadexpect(post.is_flagged?).to eq(true)@@ -151,7 +151,21 @@ describe Post doexpect(post.is_flagged?).to eq(false)end- it 'has_active_flag is accurate' do+ it 'is_flagged? is true if flag was deferred' do+ PostAction.act(user, post, PostActionType.types[:off_topic])+ PostAction.defer_flags!(post.reload, admin)+ post.reload+ expect(post.is_flagged?).to eq(true)+ end++ it 'is_flagged? is true if flag was cleared' do+ PostAction.act(user, post, PostActionType.types[:off_topic])+ PostAction.clear_flags!(post.reload, admin)+ post.reload+ expect(post.is_flagged?).to eq(true)+ end++ it 'has_active_flag? is false for deferred flags' doPostAction.act(user, post, PostActionType.types[:spam])post.reloadexpect(post.has_active_flag?).to eq(true)@@ -160,6 +174,13 @@ describe Post dopost.reloadexpect(post.has_active_flag?).to eq(false)end++ it 'has_active_flag? is false for cleared flags' do+ PostAction.act(user, post, PostActionType.types[:spam])+ PostAction.clear_flags!(post.reload, admin)+ post.reload+ expect(post.has_active_flag?).to eq(false)+ endenddescribe "maximum images" do