mirror of
https://github.com/discourse/discourse.git
synced 2025-06-14 12:50:00 +08:00
UX: Improve email testing admin tool. (#6308)
This commit is contained in:

committed by
Régis Hanol

parent
c1a5a7504e
commit
72ffabf619
@ -28,16 +28,14 @@ export default Ember.Controller.extend({
|
|||||||
sentTestEmail: false
|
sentTestEmail: false
|
||||||
});
|
});
|
||||||
|
|
||||||
var self = this;
|
|
||||||
ajax("/admin/email/test", {
|
ajax("/admin/email/test", {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: { email_address: this.get("testEmailAddress") }
|
data: { email_address: this.get("testEmailAddress") }
|
||||||
})
|
})
|
||||||
.then(
|
.then(response =>
|
||||||
function() {
|
this.set("sentTestEmailMessage", response.send_test_email_message)
|
||||||
self.set("sentTestEmail", true);
|
)
|
||||||
},
|
.catch(e => {
|
||||||
function(e) {
|
|
||||||
if (e.responseJSON && e.responseJSON.errors) {
|
if (e.responseJSON && e.responseJSON.errors) {
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
I18n.t("admin.email.error", {
|
I18n.t("admin.email.error", {
|
||||||
@ -47,11 +45,8 @@ export default Ember.Controller.extend({
|
|||||||
} else {
|
} else {
|
||||||
bootbox.alert(I18n.t("admin.email.test_error"));
|
bootbox.alert(I18n.t("admin.email.test_error"));
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
.finally(() => this.set("sendingEmail", false));
|
||||||
.finally(function() {
|
|
||||||
self.set("sendingEmail", false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class='controls'>
|
<div class='controls'>
|
||||||
<button class='btn btn-primary' {{action "sendTestEmail"}} disabled={{sendTestEmailDisabled}}>{{i18n 'admin.email.send_test'}}</button>
|
<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>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,7 +11,13 @@ class Admin::EmailController < Admin::AdminController
|
|||||||
params.require(:email_address)
|
params.require(:email_address)
|
||||||
begin
|
begin
|
||||||
Jobs::TestEmail.new.execute(to_address: params[:email_address])
|
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
|
rescue => e
|
||||||
render json: { errors: [e.message] }, status: 422
|
render json: { errors: [e.message] }, status: 422
|
||||||
end
|
end
|
||||||
|
@ -1963,6 +1963,12 @@ en:
|
|||||||
totp: "Use an authenticator app instead"
|
totp: "Use an authenticator app instead"
|
||||||
backup_code: "Use a backup code 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:
|
user:
|
||||||
deactivated: "Was deactivated due to too many bounced emails to '%{email}'."
|
deactivated: "Was deactivated due to too many bounced emails to '%{email}'."
|
||||||
deactivated_by_staff: "Deactivated by staff"
|
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')
|
expect(ActionMailer::Base.deliveries.map(&:to).flatten).to include('eviltrout@test.domain')
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
describe '#preview_digest' do
|
describe '#preview_digest' do
|
||||||
|
Reference in New Issue
Block a user