FIX: Allow sending test e-mails to any email address when disable_email is set to non-staff (#6792)

This commit is contained in:
Rishabh 2018-12-18 20:42:05 +05:30 committed by Régis Hanol
parent 32784ad11a
commit c279792130
5 changed files with 5 additions and 12 deletions

View File

@ -13,8 +13,6 @@ 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

View File

@ -2055,7 +2055,6 @@ 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}'."

View File

@ -30,10 +30,6 @@ 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
if @message.text_part if @message.text_part
if @message.text_part.body.to_s.blank? if @message.text_part.body.to_s.blank?
return skip(SkippedEmailLog.reason_types[:sender_text_part_body_blank]) return skip(SkippedEmailLog.reason_types[:sender_text_part_body_blank])

View File

@ -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 "doesn't deliver mail to normal user" do it "delivers mail to normal user" do
Mail::Message.any_instance.expects(:deliver_now).never Mail::Message.any_instance.expects(:deliver_now).once
message = Mail::Message.new(to: user.email, body: "hello") message = Mail::Message.new(to: user.email, body: "hello")
expect(Email::Sender.new(message, :hello).send).to eq(nil) Email::Sender.new(message, :hello).send
end end
it "delivers mail to staff user" do it "delivers mail to staff user" do

View File

@ -120,7 +120,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 staff only when setting is "non-staff"' do it 'sends mail to everyone 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 }
@ -129,7 +129,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_disabled_for_non_staff")) expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
end end
it 'sends mail to everyone when setting is "no"' do it 'sends mail to everyone when setting is "no"' do