diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb index 4ea646aea72..cf5829b611b 100644 --- a/app/models/reviewable_flagged_post.rb +++ b/app/models/reviewable_flagged_post.rb @@ -211,7 +211,8 @@ class ReviewableFlaggedPost < Reviewable def perform_delete_and_ignore_replies(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 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) 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 replies.each { |reply| PostDestroyer.new(performed_by, reply).destroy } diff --git a/spec/models/reviewable_flagged_post_spec.rb b/spec/models/reviewable_flagged_post_spec.rb index 9a6b185069a..4ca31603315 100644 --- a/spec/models/reviewable_flagged_post_spec.rb +++ b/spec/models/reviewable_flagged_post_spec.rb @@ -131,6 +131,12 @@ RSpec.describe ReviewableFlaggedPost, type: :model do reply_to_post_number: post.post_number, 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 reviewable.perform(moderator, :delete_and_ignore_replies) @@ -138,6 +144,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do expect(score.reload).to be_ignored expect(post.reload.deleted_at).to be_present expect(reply.reload.deleted_at).to be_present + expect(nested_reply.reload.deleted_at).to be_present end 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, 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 reviewable.perform(moderator, :delete_and_agree_replies) @@ -161,6 +174,7 @@ RSpec.describe ReviewableFlaggedPost, type: :model do expect(score.reload).to be_agreed expect(post.reload.deleted_at).to be_present expect(reply.reload.deleted_at).to be_present + expect(nested_reply.reload.deleted_at).to be_present end it "disagrees with the flags" do