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 IncomingEmail from 'admin/models/incoming-email';
|
||||||
import computed from 'ember-addons/ember-computed-decorators';
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
import { longDate } from 'discourse/lib/formatter';
|
import { longDate } from 'discourse/lib/formatter';
|
||||||
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||||
|
|
||||||
export default Ember.Controller.extend(ModalFunctionality, {
|
export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
|
|
||||||
|
@ -15,7 +16,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
||||||
},
|
},
|
||||||
|
|
||||||
loadFromBounced(id) {
|
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
|
def incoming_from_bounced
|
||||||
params.require(:id)
|
params.require(:id)
|
||||||
|
|
||||||
bounced = EmailLog.find(params[:id].to_i)
|
begin
|
||||||
email_local_part, email_domain = SiteSetting.notification_email.split('@')
|
bounced = EmailLog.find_by(id: params[:id].to_i)
|
||||||
bounced_to_address = "#{email_local_part}+verp-#{bounced.bounce_key}@#{email_domain}"
|
raise Discourse::InvalidParameters if bounced.nil?
|
||||||
|
|
||||||
incoming_email = IncomingEmail.find_by(to_addresses: bounced_to_address)
|
email_local_part, email_domain = SiteSetting.notification_email.split('@')
|
||||||
serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false)
|
bounced_to_address = "#{email_local_part}+verp-#{bounced.bounce_key}@#{email_domain}"
|
||||||
render_json_dump(serializer)
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in New Issue