mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:52:11 +08:00
UX: Improve email testing admin tool. (#6308)
This commit is contained in:
parent
c1a5a7504e
commit
72ffabf619
|
@ -28,30 +28,25 @@ export default Ember.Controller.extend({
|
|||
sentTestEmail: false
|
||||
});
|
||||
|
||||
var self = this;
|
||||
ajax("/admin/email/test", {
|
||||
type: "POST",
|
||||
data: { email_address: this.get("testEmailAddress") }
|
||||
})
|
||||
.then(
|
||||
function() {
|
||||
self.set("sentTestEmail", true);
|
||||
},
|
||||
function(e) {
|
||||
if (e.responseJSON && e.responseJSON.errors) {
|
||||
bootbox.alert(
|
||||
I18n.t("admin.email.error", {
|
||||
server_error: e.responseJSON.errors[0]
|
||||
})
|
||||
);
|
||||
} else {
|
||||
bootbox.alert(I18n.t("admin.email.test_error"));
|
||||
}
|
||||
}
|
||||
.then(response =>
|
||||
this.set("sentTestEmailMessage", response.send_test_email_message)
|
||||
)
|
||||
.finally(function() {
|
||||
self.set("sendingEmail", false);
|
||||
});
|
||||
.catch(e => {
|
||||
if (e.responseJSON && e.responseJSON.errors) {
|
||||
bootbox.alert(
|
||||
I18n.t("admin.email.error", {
|
||||
server_error: e.responseJSON.errors[0]
|
||||
})
|
||||
);
|
||||
} else {
|
||||
bootbox.alert(I18n.t("admin.email.test_error"));
|
||||
}
|
||||
})
|
||||
.finally(() => this.set("sendingEmail", false));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
</div>
|
||||
<div class='controls'>
|
||||
<button class='btn btn-primary' {{action "sendTestEmail"}} disabled={{sendTestEmailDisabled}}>{{i18n 'admin.email.send_test'}}</button>
|
||||
{{#if sentTestEmail}}<span class='result-message'>{{i18n 'admin.email.sent_test'}}</span>{{/if}}
|
||||
{{#if sentTestEmailMessage}}<span class='result-message'>{{sentTestEmailMessage}}</span>{{/if}}
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,13 @@ class Admin::EmailController < Admin::AdminController
|
|||
params.require(:email_address)
|
||||
begin
|
||||
Jobs::TestEmail.new.execute(to_address: params[:email_address])
|
||||
render body: nil
|
||||
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
|
||||
rescue => e
|
||||
render json: { errors: [e.message] }, status: 422
|
||||
end
|
||||
|
|
|
@ -1963,6 +1963,12 @@ en:
|
|||
totp: "Use an authenticator app instead"
|
||||
backup_code: "Use a backup code instead"
|
||||
|
||||
admin:
|
||||
email:
|
||||
sent_test: "sent!"
|
||||
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:
|
||||
deactivated: "Was deactivated due to too many bounced emails to '%{email}'."
|
||||
deactivated_by_staff: "Deactivated by staff"
|
||||
|
|
|
@ -106,6 +106,41 @@ describe Admin::EmailController do
|
|||
expect(ActionMailer::Base.deliveries.map(&:to).flatten).to include('eviltrout@test.domain')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with SiteSetting.disable_emails' do
|
||||
let(:eviltrout) { Fabricate(:evil_trout) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
it 'does not sends mail to anyone when setting is "yes"' do
|
||||
SiteSetting.disable_emails = 'yes'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: admin.email }
|
||||
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled"))
|
||||
end
|
||||
|
||||
it 'sends mail to staff only when setting is "non-staff"' do
|
||||
SiteSetting.disable_emails = 'non-staff'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: admin.email }
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test_disabled_for_non_staff"))
|
||||
end
|
||||
|
||||
it 'sends mail to everyone when setting is "no"' do
|
||||
SiteSetting.disable_emails = 'no'
|
||||
|
||||
post "/admin/email/test.json", params: { email_address: eviltrout.email }
|
||||
|
||||
incoming = JSON.parse(response.body)
|
||||
expect(incoming['sent_test_email_message']).to eq(I18n.t("admin.email.sent_test"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#preview_digest' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user