FEATURE: Clarify Reviewable User Actions

FEATURE: Clarify Reviewable User Actions

“Approve” is now “Approve User” and “Delete” is a dropdown with a choice that allows you to block.

diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 976ea91..8cd5a0f 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -293,12 +293,12 @@ class Admin::UsersController < Admin::AdminController
     reviewable = ReviewableUser.find_by(target: @user) ||
       Jobs::CreateUserReviewable.new.execute(user_id: @user.id).reviewable
 
-    reviewable.perform(current_user, :approve)
+    reviewable.perform(current_user, :approve_user)
     render body: nil
   end
 
   def approve_bulk
-    Reviewable.bulk_perform_targets(current_user, :approve, 'ReviewableUser', params[:users])
+    Reviewable.bulk_perform_targets(current_user, :approve_user, 'ReviewableUser', params[:users])
     render body: nil
   end
 
diff --git a/app/jobs/scheduled/auto_queue_handler.rb b/app/jobs/scheduled/auto_queue_handler.rb
index ff7d6ea..46072b8 100644
--- a/app/jobs/scheduled/auto_queue_handler.rb
+++ b/app/jobs/scheduled/auto_queue_handler.rb
@@ -15,8 +15,10 @@ module Jobs
 
         if reviewable.is_a?(ReviewableFlaggedPost)
           reviewable.perform(Discourse.system_user, :ignore)
-        else
+        elsif reviewable.is_a?(ReviewableQueuedPost)
           reviewable.perform(Discourse.system_user, :reject)
+        elsif reviewable.is_a?(ReviewableUser)
+          reviewable.perform(Discourse.system_user, :reject_user_delete)
         end
       end
     end
diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb
index 66d2352..ce80b21 100644
--- a/app/models/invite_redeemer.rb
+++ b/app/models/invite_redeemer.rb
@@ -127,7 +127,7 @@ InviteRedeemer = Struct.new(:invite, :username, :name, :password, :user_custom_f
     if invited_user.present? && reviewable_user = ReviewableUser.find_by(target: invited_user)
       reviewable_user.perform(
         invite.invited_by,
-        :approve,
+        :approve_user,
         send_email: false,
         approved_by_invite: true
       )
diff --git a/app/models/reviewable_user.rb b/app/models/reviewable_user.rb
index d19f770..3f1f2ee 100644
--- a/app/models/reviewable_user.rb
+++ b/app/models/reviewable_user.rb
@@ -12,11 +12,31 @@ class ReviewableUser < Reviewable
   def build_actions(actions, guardian, args)
     return unless pending?
 
-    actions.add(:approve) if guardian.can_approve?(target) || args[:approved_by_invite]
-    actions.add(:reject)
+    if guardian.can_approve?(target) || args[:approved_by_invite]
+      actions.add(:approve_user) do |a|
+        a.icon = 'user-plus'
+        a.label = "reviewables.actions.approve_user.title"
+      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.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.description = "reviewables.actions.reject_user.block.description"
+    end
   end
 
-  def perform_approve(performed_by, args)
+  def perform_approve_user(performed_by, args)
     ReviewableUser.set_approved_fields!(target, performed_by)
     target.save!
 
@@ -34,14 +54,17 @@ class ReviewableUser < Reviewable
     create_result(:success, :approved)
   end
 
-  def perform_reject(performed_by, args)
-
+  def perform_reject_user_delete(performed_by, args)
     # We'll delete the user if we can
     if target.present?
       destroyer = UserDestroyer.new(performed_by)
 
       begin
-        destroyer.destroy(target)
+        delete_args = {}
+        delete_args[:block_ip] = true if args[:block_ip]
+        delete_args[:block_email] = true if args[:block_email]
+
+        destroyer.destroy(target, delete_args)
       rescue UserDestroyer::PostsExistError
         # If a user has posts, we won't delete them to preserve their content.
         # However the reviable record will be "rejected" and they will remain
@@ -53,6 +76,12 @@ class ReviewableUser < Reviewable
     create_result(:success, :rejected)
   end
 
+  def perform_reject_user_block(performed_by, args)
+    args[:block_email] = true
+    args[:block_ip] = true
+    perform_reject_user_delete(performed_by, args)
+  end
+
   # Update's the user's fields for approval but does not save. This
   # can be used when generating a new user that is approved on create
   def self.set_approved_fields!(user, approved_by)
diff --git a/app/models/user.rb b/app/models/user.rb
index f1f7989..ea0cb0b 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -421,7 +421,7 @@ class User < ActiveRecord::Base
     approved_by = User.find_by(id: approved_by) if approved_by.is_a?(Numeric)
 
     if reviewable_user = ReviewableUser.find_by(target: self)
-      result = reviewable_user.perform(approved_by, :approve, send_email: send_mail)
+      result = reviewable_user.perform(approved_by, :approve_user, send_email: send_mail)
       if result.success?
         Reviewable.set_approved_fields!(self, approved_by)
         return true
@@ -904,7 +904,7 @@ class User < ActiveRecord::Base
     self.update!(active: false)
 
     if reviewable = ReviewableUser.pending.find_by(target: self)
-      reviewable.perform(performed_by, :reject)
+      reviewable.perform(performed_by, :reject_user_delete)
     end
   end
 
diff --git a/app/serializers/reviewable_bundled_action_serializer.rb b/app/serializers/reviewable_bundled_action_serializer.rb
index 0665439..ecce2fa 100644
--- a/app/serializers/reviewable_bundled_action_serializer.rb
+++ b/app/serializers/reviewable_bundled_action_serializer.rb
@@ -3,6 +3,14 @@ class ReviewableBundledActionSerializer < ApplicationSerializer
   has_many :actions, serializer: ReviewableActionSerializer, root: 'actions'
 
   def label
-    I18n.t(object.label)
+    I18n.t(object.label, default: nil)
+  end
+
+  def include_label?
+    label.present?
+  end
+
+  def include_icon?
+    icon.present?
   end
 end
diff --git a/app/services/user_destroyer.rb b/app/services/user_destroyer.rb
index f6c40ac..900ffbb 100644
--- a/app/services/user_destroyer.rb
+++ b/app/services/user_destroyer.rb
@@ -115,7 +115,7 @@ class UserDestroyer
 
     # After the user is deleted, remove the reviewable
     if reviewable = Reviewable.pending.find_by(target: user)
-      reviewable.perform(@actor, :reject)
+      reviewable.perform(@actor, :reject_user_delete)
     end
 
     result
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index a008d44..bf274cc 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -4461,6 +4461,16 @@ en:
         title: "Ignore"
       approve:
         title: "Approve"
+      approve_user:
+        title: "Approve User"
+      reject_user:
+        title: "Delete User..."
+        delete:
+          title: "Delete User"
+          description: "The user will be deleted from the forum."
+        block:
+          title: "Delete and Block User"
+          description: "The user will be deleted, and we'll block their IP and email address."
       reject:
         title: "Reject"
       delete_user:
diff --git a/spec/models/reviewable_history_spec.rb b/spec/models/reviewable_history_spec.rb
index 735695d..bb8b7bb 100644
--- a/spec/models/reviewable_history_spec.rb
+++ b/spec/models/reviewable_history_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe ReviewableHistory, type: :model do
 
   it "adds a `created` history event when a reviewable is created" do
     reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
-    reviewable.perform(moderator, :approve)
+    reviewable.perform(moderator, :approve_user)
     reviewable = ReviewableUser.needs_review!(target: user, created_by: admin)
 
     history = reviewable.history

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

GitHub sha: 14f9d40e

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: