FIX: Correctly ignore/approve replies when acting on a flagged post (#8425)
This commit is contained in:
parent
b6e08c06c5
commit
1c9d18f094
|
@ -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
|
||||
|
||||
|
|
|
@ -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 = {})
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue