FEATURE: When suspending a user, allow the Delete + Replies action

Previously you could only delete the post
This commit is contained in:
Robin Ward 2019-05-27 12:27:16 -04:00
parent 192562745f
commit d95a68b837
6 changed files with 33 additions and 7 deletions

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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',