FIX: Respect the disable_emails=non-staff site setting correctly
This reverts commit c279792130
.
This commit inadvertently removed all of the non-staff email logic, rather than just for the 'test email' button.
https://meta.discourse.org/t/112231/5
This commit is contained in:
parent
e1e46f0dff
commit
3f9e7eb326
|
@ -13,6 +13,8 @@ class Admin::EmailController < Admin::AdminController
|
||||||
Jobs::TestEmail.new.execute(to_address: params[:email_address])
|
Jobs::TestEmail.new.execute(to_address: params[:email_address])
|
||||||
if SiteSetting.disable_emails == "yes"
|
if SiteSetting.disable_emails == "yes"
|
||||||
render json: { sent_test_email_message: I18n.t("admin.email.sent_test_disabled") }
|
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
|
else
|
||||||
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
|
render json: { sent_test_email_message: I18n.t("admin.email.sent_test") }
|
||||||
end
|
end
|
||||||
|
|
|
@ -2175,6 +2175,7 @@ en:
|
||||||
email:
|
email:
|
||||||
sent_test: "sent!"
|
sent_test: "sent!"
|
||||||
sent_test_disabled: "cannot send because emails are disabled"
|
sent_test_disabled: "cannot send because emails are disabled"
|
||||||
|
sent_test_disabled_for_non_staff: "cannot send because emails are disabled for non-staff"
|
||||||
|
|
||||||
user:
|
user:
|
||||||
deactivated: "Was deactivated due to too many bounced emails to '%{email}'."
|
deactivated: "Was deactivated due to too many bounced emails to '%{email}'."
|
||||||
|
|
|
@ -35,6 +35,10 @@ module Email
|
||||||
return skip(SkippedEmailLog.reason_types[:sender_message_blank]) if @message.blank?
|
return skip(SkippedEmailLog.reason_types[:sender_message_blank]) if @message.blank?
|
||||||
return skip(SkippedEmailLog.reason_types[:sender_message_to_blank]) if @message.to.blank?
|
return skip(SkippedEmailLog.reason_types[:sender_message_to_blank]) if @message.to.blank?
|
||||||
|
|
||||||
|
if SiteSetting.disable_emails == "non-staff"
|
||||||
|
return unless User.find_by_email(to_address)&.staff?
|
||||||
|
end
|
||||||
|
|
||||||
return skip(SkippedEmailLog.reason_types[:sender_message_to_invalid]) if to_address.end_with?(".invalid")
|
return skip(SkippedEmailLog.reason_types[:sender_message_to_invalid]) if to_address.end_with?(".invalid")
|
||||||
|
|
||||||
if @message.text_part
|
if @message.text_part
|
||||||
|
|
|
@ -27,10 +27,10 @@ describe Email::Sender do
|
||||||
context "disable_emails is enabled for non-staff users" do
|
context "disable_emails is enabled for non-staff users" do
|
||||||
before { SiteSetting.disable_emails = "non-staff" }
|
before { SiteSetting.disable_emails = "non-staff" }
|
||||||
|
|
||||||
it "delivers mail to normal user" do
|
it "doesn't deliver mail to normal user" do
|
||||||
Mail::Message.any_instance.expects(:deliver_now).once
|
Mail::Message.any_instance.expects(:deliver_now).never
|
||||||
message = Mail::Message.new(to: user.email, body: "hello")
|
message = Mail::Message.new(to: user.email, body: "hello")
|
||||||
Email::Sender.new(message, :hello).send
|
expect(Email::Sender.new(message, :hello).send).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "delivers mail to staff user" do
|
it "delivers mail to staff user" do
|
||||||
|
|
|
@ -146,7 +146,7 @@ describe Admin::EmailController do
|
||||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled"))
|
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends mail to everyone when setting is "non-staff"' do
|
it 'sends mail to staff only when setting is "non-staff"' do
|
||||||
SiteSetting.disable_emails = 'non-staff'
|
SiteSetting.disable_emails = 'non-staff'
|
||||||
|
|
||||||
post "/admin/email/test.json", params: { email_address: admin.email }
|
post "/admin/email/test.json", params: { email_address: admin.email }
|
||||||
|
@ -155,7 +155,7 @@ describe Admin::EmailController do
|
||||||
|
|
||||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||||
incoming = JSON.parse(response.body)
|
incoming = JSON.parse(response.body)
|
||||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled_for_non_staff"))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends mail to everyone when setting is "no"' do
|
it 'sends mail to everyone when setting is "no"' do
|
||||||
|
|
Loading…
Reference in New Issue