FIX: Recursively delete nested replies
Previously we were only deleting top level replies
This commit is contained in:
parent
5edb5c8b03
commit
812905cbb6
|
@ -211,7 +211,8 @@ class ReviewableFlaggedPost < Reviewable
|
||||||
def perform_delete_and_ignore_replies(performed_by, args)
|
def perform_delete_and_ignore_replies(performed_by, args)
|
||||||
result = perform_ignore(performed_by, args)
|
result = perform_ignore(performed_by, args)
|
||||||
|
|
||||||
replies = PostReply.where(post_id: post.id).includes(:reply).map(&:reply)
|
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).destroy
|
PostDestroyer.new(performed_by, post).destroy
|
||||||
replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy }
|
replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy }
|
||||||
|
|
||||||
|
@ -227,7 +228,8 @@ class ReviewableFlaggedPost < Reviewable
|
||||||
def perform_delete_and_agree_replies(performed_by, args)
|
def perform_delete_and_agree_replies(performed_by, args)
|
||||||
result = agree(performed_by, args)
|
result = agree(performed_by, args)
|
||||||
|
|
||||||
replies = PostReply.where(post_id: post.id).includes(:reply).map(&:reply)
|
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).destroy
|
PostDestroyer.new(performed_by, post).destroy
|
||||||
replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy }
|
replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy }
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,12 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
||||||
reply_to_post_number: post.post_number,
|
reply_to_post_number: post.post_number,
|
||||||
topic_id: post.topic_id
|
topic_id: post.topic_id
|
||||||
)
|
)
|
||||||
|
nested_reply = PostCreator.create(
|
||||||
|
Fabricate(:user),
|
||||||
|
raw: 'this is the reply text2',
|
||||||
|
reply_to_post_number: reply.post_number,
|
||||||
|
topic_id: post.topic_id
|
||||||
|
)
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
reviewable.perform(moderator, :delete_and_ignore_replies)
|
reviewable.perform(moderator, :delete_and_ignore_replies)
|
||||||
|
@ -138,6 +144,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
||||||
expect(score.reload).to be_ignored
|
expect(score.reload).to be_ignored
|
||||||
expect(post.reload.deleted_at).to be_present
|
expect(post.reload.deleted_at).to be_present
|
||||||
expect(reply.reload.deleted_at).to be_present
|
expect(reply.reload.deleted_at).to be_present
|
||||||
|
expect(nested_reply.reload.deleted_at).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "delete_and_agree agrees with the flags and deletes post" do
|
it "delete_and_agree agrees with the flags and deletes post" do
|
||||||
|
@ -154,6 +161,12 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
||||||
reply_to_post_number: post.post_number,
|
reply_to_post_number: post.post_number,
|
||||||
topic_id: post.topic_id
|
topic_id: post.topic_id
|
||||||
)
|
)
|
||||||
|
nested_reply = PostCreator.create(
|
||||||
|
Fabricate(:user),
|
||||||
|
raw: 'this is the reply text2',
|
||||||
|
reply_to_post_number: reply.post_number,
|
||||||
|
topic_id: post.topic_id
|
||||||
|
)
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
reviewable.perform(moderator, :delete_and_agree_replies)
|
reviewable.perform(moderator, :delete_and_agree_replies)
|
||||||
|
@ -161,6 +174,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do
|
||||||
expect(score.reload).to be_agreed
|
expect(score.reload).to be_agreed
|
||||||
expect(post.reload.deleted_at).to be_present
|
expect(post.reload.deleted_at).to be_present
|
||||||
expect(reply.reload.deleted_at).to be_present
|
expect(reply.reload.deleted_at).to be_present
|
||||||
|
expect(nested_reply.reload.deleted_at).to be_present
|
||||||
end
|
end
|
||||||
|
|
||||||
it "disagrees with the flags" do
|
it "disagrees with the flags" do
|
||||||
|
|
Loading…
Reference in New Issue