FIX: only send user suspension emails if email message provided (#12666)

FIX: only send user suspension emails if email message provided (#12666)

This makes behavior consistent with documentation:

API:

Will send an email with this message when present

Web UI:

Optionally, provide more information about the suspension and it will be emailed to the user

diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 0e55673..d71762b 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -124,12 +124,14 @@ class Admin::UsersController < Admin::AdminController
     end
     @user.logged_out
 
-    Jobs.enqueue(
-      :critical_user_email,
-      type: :account_suspended,
-      user_id: @user.id,
-      user_history_id: user_history.id
-    )
+    if message && !message.empty?
+      Jobs.enqueue(
+        :critical_user_email,
+        type: :account_suspended,
+        user_id: @user.id,
+        user_history_id: user_history.id
+      )
+    end
 
     DiscourseEvent.trigger(
       :user_suspended,
diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb
index 68d470e..e756c6c 100644
--- a/spec/requests/admin/users_controller_spec.rb
+++ b/spec/requests/admin/users_controller_spec.rb
@@ -133,10 +133,13 @@ RSpec.describe Admin::UsersController do
 
     it "works properly" do
       expect(user).not_to be_suspended
-      put "/admin/users/#{user.id}/suspend.json", params: {
-        suspend_until: 5.hours.from_now,
-        reason: "because I said so"
-      }
+
+      expect do
+        put "/admin/users/#{user.id}/suspend.json", params: {
+          suspend_until: 5.hours.from_now,
+          reason: "because I said so"
+        }
+      end.to change { Jobs::CriticalUserEmail.jobs.size }.by(0)
 
       expect(response.status).to eq(200)
 

GitHub sha: 045adb76

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