Handle invalid parameters and missing bounced emails
This commit is contained in:
parent
5296f00c28
commit
aac4a4ed94
|
@ -2,6 +2,7 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality';
|
|||
import IncomingEmail from 'admin/models/incoming-email';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
import { longDate } from 'discourse/lib/formatter';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Controller.extend(ModalFunctionality, {
|
||||
|
||||
|
@ -15,7 +16,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
},
|
||||
|
||||
loadFromBounced(id) {
|
||||
return IncomingEmail.findByBounced(id).then(result => this.set("model", result));
|
||||
return IncomingEmail.findByBounced(id)
|
||||
.then(result => this.set("model", result))
|
||||
.catch(error => {
|
||||
this.send("closeModal");
|
||||
popupAjaxError(error);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -91,13 +91,21 @@ class Admin::EmailController < Admin::AdminController
|
|||
def incoming_from_bounced
|
||||
params.require(:id)
|
||||
|
||||
bounced = EmailLog.find(params[:id].to_i)
|
||||
begin
|
||||
bounced = EmailLog.find_by(id: params[:id].to_i)
|
||||
raise Discourse::InvalidParameters if bounced.nil?
|
||||
|
||||
email_local_part, email_domain = SiteSetting.notification_email.split('@')
|
||||
bounced_to_address = "#{email_local_part}+verp-#{bounced.bounce_key}@#{email_domain}"
|
||||
|
||||
incoming_email = IncomingEmail.find_by(to_addresses: bounced_to_address)
|
||||
raise Discourse::NotFound if incoming_email.nil?
|
||||
|
||||
serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false)
|
||||
render_json_dump(serializer)
|
||||
rescue => e
|
||||
render json: {errors: [e.message]}, status: 404
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
Loading…
Reference in New Issue