diff --git a/app/assets/javascripts/admin/components/penalty-post-action.js.es6 b/app/assets/javascripts/admin/components/penalty-post-action.js.es6 index c485364ad0f..543a8baf3c9 100644 --- a/app/assets/javascripts/admin/components/penalty-post-action.js.es6 +++ b/app/assets/javascripts/admin/components/penalty-post-action.js.es6 @@ -1,6 +1,7 @@ import computed from "ember-addons/ember-computed-decorators"; -const ACTIONS = ["delete", "edit", "none"]; +const ACTIONS = ["delete", "delete_replies", "edit", "none"]; + export default Ember.Component.extend({ postId: null, postAction: null, diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index f4235e86539..fc699c8c20f 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -551,6 +551,8 @@ class Admin::UsersController < Admin::AdminController case params[:post_action] when 'delete' PostDestroyer.new(current_user, post).destroy + when "delete_replies" + PostDestroyer.delete_with_replies(current_user, post) when 'edit' revisor = PostRevisor.new(post) diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb index 5c00228f8e3..a8eea800d3e 100644 --- a/app/models/reviewable_flagged_post.rb +++ b/app/models/reviewable_flagged_post.rb @@ -229,12 +229,7 @@ class ReviewableFlaggedPost < Reviewable def perform_delete_and_agree_replies(performed_by, args) result = agree(performed_by, args) - - 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 } - + PostDestroyer.delete_with_replies(performed_by, post) result end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index dbbf6dda3e7..f11cf849bde 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3877,6 +3877,7 @@ en: delete_posts_failed: "There was a problem deleting the posts." penalty_post_actions: "What would you like to do with the associated post?" penalty_post_delete: "Delete the post" + penalty_post_delete_replies: "Delete the post + any replies" penalty_post_edit: "Edit the post" penalty_post_none: "Do nothing" penalty_count: "Penalty Count" diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb index ddd03120902..e0c5ff3991c 100644 --- a/lib/post_destroyer.rb +++ b/lib/post_destroyer.rb @@ -39,6 +39,13 @@ class PostDestroyer end end + def self.delete_with_replies(performed_by, post) + 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 } + end + def initialize(user, post, opts = {}) @user = user @post = post diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index 53e483f0f4d..718b735e51c 100644 --- a/spec/requests/admin/users_controller_spec.rb +++ b/spec/requests/admin/users_controller_spec.rb @@ -185,6 +185,26 @@ RSpec.describe Admin::UsersController do expect(response.status).to eq(200) end + it "can delete an associated post and its replies" do + reply = PostCreator.create( + Fabricate(:user), + raw: 'this is the reply text', + 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 + ) + put "/admin/users/#{user.id}/suspend.json", params: suspend_params.merge(post_action: 'delete_replies') + 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 + expect(response.status).to eq(200) + end + it "can edit an associated post" do put "/admin/users/#{user.id}/suspend.json", params: suspend_params.merge( post_action: 'edit',