FIX: don't send PM if flagged post is deleted but flags were deferred or cleared

This commit is contained in:
Neil Lalonde 2018-07-26 15:12:12 -04:00
parent 330cf78c83
commit 135c803f49
3 changed files with 34 additions and 3 deletions

View File

@ -196,7 +196,7 @@ class PostDestroyer
end
def 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,

View File

@ -606,6 +606,16 @@ describe PostDestroyer do
Topic.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)
end
end
describe "user actions" do

View File

@ -141,7 +141,7 @@ describe Post do
let(:user) { Fabricate(:coding_horror) }
let(:admin) { Fabricate(:admin) }
it 'isFlagged is accurate' do
it 'is_flagged? is accurate' do
PostAction.act(user, post, PostActionType.types[:off_topic])
post.reload
expect(post.is_flagged?).to eq(true)
@ -151,7 +151,21 @@ describe Post do
expect(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' do
PostAction.act(user, post, PostActionType.types[:spam])
post.reload
expect(post.has_active_flag?).to eq(true)
@ -160,6 +174,13 @@ describe Post do
post.reload
expect(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)
end
end
describe "maximum images" do