FIX: Correctly ignore/approve replies when acting on a flagged post (#8425)

This commit is contained in:
Roman Rizzi 2019-11-27 17:19:44 -03:00 committed by GitHub
parent b6e08c06c5
commit 1c9d18f094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

@ -228,7 +228,7 @@ class ReviewableFlaggedPost < Reviewable
def perform_delete_and_agree_replies(performed_by, args)
result = agree(performed_by, args)
PostDestroyer.delete_with_replies(performed_by, post, self)
PostDestroyer.delete_with_replies(performed_by, post, self, defer_reply_flags: false)
result
end

View File

@ -39,11 +39,11 @@ class PostDestroyer
end
end
def self.delete_with_replies(performed_by, post, reviewable = nil)
def self.delete_with_replies(performed_by, post, reviewable = nil, defer_reply_flags: true)
reply_ids = post.reply_ids(Guardian.new(performed_by), only_replies_to_single_post: false)
replies = Post.where(id: reply_ids.map { |r| r[:id] })
PostDestroyer.new(performed_by, post, reviewable: reviewable).destroy
replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy }
replies.each { |reply| PostDestroyer.new(performed_by, reply, defer_flags: defer_reply_flags).destroy }
end
def initialize(user, post, opts = {})

View File

@ -798,4 +798,28 @@ describe PostDestroyer do
end
end
describe '#delete_with_replies' do
let(:reporter) { Discourse.system_user }
fab!(:post) { Fabricate(:post) }
before do
reply = Fabricate(:post, topic: post.topic)
post.update(replies: [reply])
PostActionCreator.off_topic(reporter, post)
@reviewable_reply = PostActionCreator.off_topic(reporter, reply).reviewable
end
it 'ignores flagged replies' do
PostDestroyer.delete_with_replies(reporter, post)
expect(@reviewable_reply.reload.status).to eq Reviewable.statuses[:ignored]
end
it 'approves flagged replies' do
PostDestroyer.delete_with_replies(reporter, post, defer_reply_flags: false)
expect(@reviewable_reply.reload.status).to eq Reviewable.statuses[:approved]
end
end
end