From cf4c256b17d295b24fc4ff38d3d05aebb81eb37d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 1 Feb 2016 21:41:49 +0100 Subject: [PATCH] FEATURE: new 'raw email' modal when listing rejected emails --- .../admin/models/incoming-email.js.es6 | 4 ++++ .../admin/routes/admin-email-rejected.js.es6 | 14 +++++++++++++- .../admin/templates/email-rejected.hbs | 4 +++- .../discourse/controllers/raw-email.js.es6 | 15 ++++++++++----- .../javascripts/discourse/models/post.js.es6 | 3 +-- app/controllers/admin/email_controller.rb | 6 ++++++ app/controllers/posts_controller.rb | 2 +- config/routes.rb | 1 + lib/email/receiver.rb | 10 +++------- 9 files changed, 42 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/admin/models/incoming-email.js.es6 b/app/assets/javascripts/admin/models/incoming-email.js.es6 index 677fbebbc..d0e5b43c5 100644 --- a/app/assets/javascripts/admin/models/incoming-email.js.es6 +++ b/app/assets/javascripts/admin/models/incoming-email.js.es6 @@ -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`); } }); diff --git a/app/assets/javascripts/admin/routes/admin-email-rejected.js.es6 b/app/assets/javascripts/admin/routes/admin-email-rejected.js.es6 index ed662e211..4d96868d2 100644 --- a/app/assets/javascripts/admin/routes/admin-email-rejected.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-email-rejected.js.es6 @@ -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); + } + } + +}); diff --git a/app/assets/javascripts/admin/templates/email-rejected.hbs b/app/assets/javascripts/admin/templates/email-rejected.hbs index 6e055ffb2..ea5c22112 100644 --- a/app/assets/javascripts/admin/templates/email-rejected.hbs +++ b/app/assets/javascripts/admin/templates/email-rejected.hbs @@ -41,7 +41,9 @@ {{/each}} {{email.subject}} - {{email.error}} + + {{email.error}} + {{else}} {{i18n 'admin.email.incoming_emails.none'}} diff --git a/app/assets/javascripts/discourse/controllers/raw-email.js.es6 b/app/assets/javascripts/discourse/controllers/raw-email.js.es6 index caf410fd5..29ea5adc2 100644 --- a/app/assets/javascripts/discourse/controllers/raw-email.js.es6 +++ b/app/assets/javascripts/discourse/controllers/raw-email.js.es6 @@ -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)); } }); diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index d55075d06..ff638cef6 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -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`); } }); diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index 4f9837e8b..c8c603e9f 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -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) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 553e0e036..f9800e885 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -79,7 +79,7 @@ class PostsController < ApplicationController def raw_email post = Post.find(params[:id].to_i) guardian.ensure_can_view_raw_email!(post) - render json: {raw_email: post.raw_email} + render json: { raw_email: post.raw_email } end def short_link diff --git a/config/routes.rb b/config/routes.rb index daf6ba56b..49d7a623e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 50cc7998f..049f7fcff 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -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)