FEATURE: new 'raw email' modal when listing rejected emails

This commit is contained in:
Régis Hanol 2016-02-01 21:41:49 +01:00
parent de58e58272
commit cf4c256b17
9 changed files with 42 additions and 17 deletions

View file

@ -23,6 +23,10 @@ IncomingEmail.reopenClass({
return Discourse.ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
.then(incomings => _.map(incomings, incoming => IncomingEmail.create(incoming)));
},
loadRawEmail(id) {
return Discourse.ajax(`/admin/email/incoming/${id}/raw.json`);
}
});

View file

@ -1,2 +1,14 @@
import showModal from 'discourse/lib/show-modal';
import AdminEmailIncomings from 'admin/routes/admin-email-incomings';
export default AdminEmailIncomings.extend({ status: "rejected" });
export default AdminEmailIncomings.extend({
status: "rejected",
actions: {
showRawEmail(incomingEmailId) {
showModal('raw-email');
this.controllerFor('raw_email').loadIncomingRawEmail(incomingEmailId);
}
}
});

View file

@ -41,7 +41,9 @@
{{/each}}
</td>
<td>{{email.subject}}</td>
<td class="error">{{email.error}}</td>
<td class="error">
<a {{action "showRawEmail" email.id}}>{{email.error}}</a>
</td>
</tr>
{{else}}
<tr><td colspan="5">{{i18n 'admin.email.incoming_emails.none'}}</td></tr>

View file

@ -1,14 +1,19 @@
import ModalFunctionality from 'discourse/mixins/modal-functionality';
import Post from 'discourse/models/post';
import IncomingEmail from 'admin/models/incoming-email';
// This controller handles displaying of raw email
export default Ember.Controller.extend(ModalFunctionality, {
rawEmail: "",
loadRawEmail: function(postId) {
var self = this;
Discourse.Post.loadRawEmail(postId).then(function (result) {
self.set("rawEmail", result);
});
loadRawEmail(postId) {
return Post.loadRawEmail(postId)
.then(result => this.set("rawEmail", result.raw_email));
},
loadIncomingRawEmail(incomingEmailId) {
return IncomingEmail.loadRawEmail(incomingEmailId)
.then(result => this.set("rawEmail", result.raw_email));
}
});

View file

@ -427,8 +427,7 @@ Post.reopenClass({
},
loadRawEmail(postId) {
return Discourse.ajax("/posts/" + postId + "/raw-email")
.then(result => result.raw_email);
return Discourse.ajax(`/posts/${postId}/raw-email.json`);
}
});

View file

@ -51,6 +51,12 @@ class Admin::EmailController < Admin::AdminController
render text: "email was processed"
end
def raw_email
params.require(:id)
incoming_email = IncomingEmail.find(params[:id].to_i)
render json: { raw_email: incoming_email.raw }
end
private
def filter_email_logs(email_logs, params)

View file

@ -123,6 +123,7 @@ Discourse::Application.routes.draw do
get "skipped"
get "received"
get "rejected"
get "/incoming/:id/raw" => "email#raw_email"
get "preview-digest" => "email#preview_digest"
post "handle_mail"
end

View file

@ -48,16 +48,12 @@ module Email
end
def process_internal
raise AutoGeneratedEmailError if is_auto_generated?
user = find_or_create_user(from)
@incoming_email.update_columns(user_id: user.id)
body = select_body || ""
raise AutoGeneratedEmailError if is_auto_generated?
raise NoBodyDetectedError if body.blank? && !@mail.has_attachments?
user = find_or_create_user(from)
@incoming_email.update_columns(user_id: user.id)
raise InactiveUserError if !user.active && !user.staged
if action = subscription_action_for(body, subject)