FIX: Prevent critical emails bypassing disable, and improve email test logic

- The test_email job is removed, because it was always being run synchronously (not in sidekiq)
- 34b29f62 added a bypass for critical emails, to match the spec. This removes the bypass, and removes the spec.
- This adapts the specs for 72ffabf6, so that they check for emails being sent
- This reimplements c2797921, allowing test emails to be sent even when emails are disabled
This commit is contained in:
David Taylor
2019-03-21 21:57:09 +00:00
committed by Guo Xiang Tan
parent 48d0465f72
commit a9d5ffbe3d
9 changed files with 46 additions and 91 deletions

View File

@ -10,14 +10,10 @@ class Admin::EmailController < Admin::AdminController
def test
params.require(:email_address)
begin
Jobs::TestEmail.new.execute(to_address: params[:email_address])
if SiteSetting.disable_emails == "yes"
render json: { sent_test_email_message: I18n.t("admin.email.sent_test_disabled") }
elsif SiteSetting.disable_emails == "non-staff" && !User.find_by_email(params[:email_address])&.staff?
render json: { sent_test_email_message: I18n.t("admin.email.sent_test_disabled_for_non_staff") }
else
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
end
message = TestMailer.send_test(params[:email_address])
Email::Sender.new(message, :test_message).send
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
rescue => e
render json: { errors: [e.message] }, status: 422
end