FEATURE: Blocking is optional when deleting a user from the review queue. (#13375)

FEATURE: Blocking is optional when deleting a user from the review queue. (#13375)

Subclasses must call #delete_user_actions inside build_actions to support user deletion. The method adds a delete user bundle, which has a delete and a delete + block option. Every subclass is responsible for implementing these actions.

diff --git a/app/jobs/scheduled/auto_queue_handler.rb b/app/jobs/scheduled/auto_queue_handler.rb
index 500a45b..dfc87b7 100644
--- a/app/jobs/scheduled/auto_queue_handler.rb
+++ b/app/jobs/scheduled/auto_queue_handler.rb
@@ -20,7 +20,7 @@ module Jobs
         elsif reviewable.is_a?(ReviewableQueuedPost)
           reviewable.perform(Discourse.system_user, :reject_post)
         elsif reviewable.is_a?(ReviewableUser)
-          reviewable.perform(Discourse.system_user, :reject_user_delete)
+          reviewable.perform(Discourse.system_user, :delete_user)
         end
       end
     end
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 3fc8364..6876462 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -643,6 +643,28 @@ class Reviewable < ActiveRecord::Base
     self.score
   end
 
+  def delete_user_actions(actions, require_reject_reason: false)
+    reject = actions.add_bundle(
+      'reject_user',
+      icon: 'user-times',
+      label: 'reviewables.actions.reject_user.title'
+    )
+
+    actions.add(:delete_user, bundle: reject) do |a|
+      a.icon = 'user-times'
+      a.label = "reviewables.actions.reject_user.delete.title"
+      a.require_reject_reason = require_reject_reason
+      a.description = "reviewables.actions.reject_user.delete.description"
+    end
+
+    actions.add(:delete_user_block, bundle: reject) do |a|
+      a.icon = 'ban'
+      a.label = "reviewables.actions.reject_user.block.title"
+      a.require_reject_reason = require_reject_reason
+      a.description = "reviewables.actions.reject_user.block.description"
+    end
+  end
+
 protected
 
   def increment_version!(version = nil)
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index dada954..f2971e7 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -57,16 +57,6 @@ class ReviewableFlaggedPost < Reviewable
       build_action(actions, :agree_and_silence, icon: 'microphone-slash', bundle: agree, client_action: 'silence')
     end
 
-    if can_delete_spammer = potential_spam? && guardian.can_delete_all_posts?(target_created_by)
-      build_action(
-        actions,
-        :delete_spammer,
-        icon: 'exclamation-triangle',
-        bundle: agree,
-        confirm: true
-      )
-    end
-
     if post.user_deleted?
       build_action(actions, :agree_and_restore, icon: 'far-eye', bundle: agree)
     end
@@ -79,6 +69,10 @@ class ReviewableFlaggedPost < Reviewable
 
     build_action(actions, :ignore, icon: 'external-link-alt')
 
+    if potential_spam? && guardian.can_delete_all_posts?(target_created_by)
+      delete_user_actions(actions)
+    end
+
     if guardian.can_delete_post_or_topic?(post)
       delete = actions.add_bundle("#{id}-delete", icon: "far-trash-alt", label: "reviewables.actions.delete.title")
       build_action(actions, :delete_and_ignore, icon: 'external-link-alt', bundle: delete)
@@ -134,17 +128,22 @@ class ReviewableFlaggedPost < Reviewable
     agree(performed_by, args)
   end
 
-  def perform_delete_spammer(performed_by, args)
-    UserDestroyer.new(performed_by).destroy(
-      post.user,
-      delete_posts: true,
-      prepare_for_destroy: true,
-      block_email: true,
-      block_urls: true,
-      block_ip: true,
-      delete_as_spammer: true,
-      context: "review"
-    )
+  def perform_delete_user(performed_by, args)
+    delete_options = delete_opts
+
+    UserDestroyer.new(performed_by).destroy(post.user, delete_options)
+
+    agree(performed_by, args)
+  end
+
+  def perform_delete_user_block(performed_by, args)
+    delete_options = delete_opts
+
+    if Rails.env.production?
+      delete_options.merge!(block_email: true, block_ip: true)
+    end
+
+    UserDestroyer.new(performed_by).destroy(post.user, delete_options)
 
     agree(performed_by, args)
   end
@@ -302,6 +301,16 @@ protected
 
 private
 
+  def delete_opts
+    {
+      delete_posts: true,
+      prepare_for_destroy: true,
+      block_urls: true,
+      delete_as_spammer: true,
+      context: "review"
+    }
+  end
+
   def destroyer(performed_by, post)
     PostDestroyer.new(performed_by, post, reviewable: self)
   end
diff --git a/app/models/reviewable_queued_post.rb b/app/models/reviewable_queued_post.rb
index 1055594..da791f6 100644
--- a/app/models/reviewable_queued_post.rb
+++ b/app/models/reviewable_queued_post.rb
@@ -33,12 +33,7 @@ class ReviewableQueuedPost < Reviewable
     end
 
     if pending? && guardian.can_delete_user?(created_by)
-      actions.add(:delete_user) do |action|
-        action.icon = 'trash-alt'
-        action.button_class = 'btn-danger'
-        action.label = 'reviewables.actions.delete_user.title'
-        action.confirm_message = 'reviewables.actions.delete_user.confirm'
-      end
+      delete_user_actions(actions)
     end
 
     actions.add(:delete) if guardian.can_delete?(self)
@@ -133,24 +128,35 @@ class ReviewableQueuedPost < Reviewable
   end
 
   def perform_delete_user(performed_by, args)
-    delete_options = {
-      context: I18n.t('reviewables.actions.delete_user.reason'),
-      delete_posts: true,
-      block_urls: true,
-      block_email: true,
-      block_ip: true,
-      delete_as_spammer: true
-    }
+    delete_user(performed_by, delete_opts)
+  end
+
+  def perform_delete_user_block(performed_by, args)
+    delete_options = delete_opts
 
     if Rails.env.production?
       delete_options.merge!(block_email: true, block_ip: true)
     end
 
+    delete_user(performed_by, delete_options)
+  end
+
+  private
+
+  def delete_user(performed_by, delete_options)
     reviewable_ids = Reviewable.where(created_by: created_by).pluck(:id)
     UserDestroyer.new(performed_by).destroy(created_by, delete_options)
     create_result(:success) { |r| r.remove_reviewable_ids = reviewable_ids }
   end
 
+  def delete_opts
+    {
+      context: I18n.t('reviewables.actions.delete_user.reason'),
+      delete_posts: true,
+      block_urls: true,
+      delete_as_spammer: true
+    }
+  end
 end
 
 # == Schema Information
diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rb
index 93291bf..a2325a2 100644
--- a/app/models/reviewable_user.rb
+++ b/app/models/reviewable_user.rb
@@ -19,23 +19,7 @@ class ReviewableUser < Reviewable
       end
     end
 
-    reject = actions.add_bundle(
-      'reject_user',
-      icon: 'user-times',
-      label: 'reviewables.actions.reject_user.title'
-    )
-    actions.add(:reject_user_delete, bundle: reject) do |a|
-      a.icon = 'user-times'
-      a.label = "reviewables.actions.reject_user.delete.title"
-      a.require_reject_reason = !is_a_suspect_user?
-      a.description = "reviewables.actions.reject_user.delete.description"
-    end
-    actions.add(:reject_user_block, bundle: reject) do |a|
-      a.icon = 'ban'
-      a.label = "reviewables.actions.reject_user.block.title"
-      a.require_reject_reason = !is_a_suspect_user?
-      a.description = "reviewables.actions.reject_user.block.description"
-    end
+    delete_user_actions(actions, require_reject_reason: !is_a_suspect_user?)
   end
 
   def perform_approve_user(performed_by, args)
@@ -56,7 +40,7 @@ class ReviewableUser < Reviewable
     create_result(:success, :approved)
   end
 
-  def perform_reject_user_delete(performed_by, args)
+  def perform_delete_user(performed_by, args)
     # We'll delete the user if we can
     if target.present?
       destroyer = UserDestroyer.new(performed_by)
@@ -96,10 +80,10 @@ class ReviewableUser < Reviewable
     create_result(:success, :rejected)
   end
 
-  def perform_reject_user_block(performed_by, args)
+  def perform_delete_user_block(performed_by, args)
     args[:block_email] = true
     args[:block_ip] = true
-    perform_reject_user_delete(performed_by, args)
+    perform_delete_user(performed_by, args)
   end
 
   # Update's the user's fields for approval but does not save. This

[... diff too long, it was truncated ...]

GitHub sha: 4dc8c3c409138847ee48a81af0d8ec00feb136df

This commit appears in #13375 which was approved by eviltrout. It was merged by romanrizzi.