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
This commit is contained in:
Ryan Mulligan 2021-04-12 08:03:10 -07:00 committed by GitHub
parent 65647000a1
commit 045adb76f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

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

View File

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