From 5ad0813322820a6c42d7b3074531ac40108bfb69 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 28 Sep 2018 11:32:44 -0700 Subject: [PATCH] Add rerouting option --- .../action_mailroom/reroutes_controller.rb | 14 ++++++++++++++ .../action_mailroom/inbound_email/routable.rb | 7 +++---- .../action_mailroom/inbound_emails/show.html.erb | 4 +++- config/routes.rb | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/controllers/rails/conductor/action_mailroom/reroutes_controller.rb diff --git a/app/controllers/rails/conductor/action_mailroom/reroutes_controller.rb b/app/controllers/rails/conductor/action_mailroom/reroutes_controller.rb new file mode 100644 index 0000000000..028ed9e2d6 --- /dev/null +++ b/app/controllers/rails/conductor/action_mailroom/reroutes_controller.rb @@ -0,0 +1,14 @@ +class Rails::Conductor::ActionMailroom::ReroutesController < Rails::Conductor::BaseController + def create + inbound_email = ActionMailroom::InboundEmail.find(params[:inbound_email_id]) + reroute inbound_email + + redirect_to main_app.rails_conductor_inbound_email_url(inbound_email) + end + + private + def reroute(inbound_email) + inbound_email.pending! + inbound_email.route_later + end +end diff --git a/app/models/action_mailroom/inbound_email/routable.rb b/app/models/action_mailroom/inbound_email/routable.rb index 61a14a0ba1..5075db326e 100644 --- a/app/models/action_mailroom/inbound_email/routable.rb +++ b/app/models/action_mailroom/inbound_email/routable.rb @@ -5,8 +5,7 @@ module ActionMailroom::InboundEmail::Routable after_create_commit :route_later, if: ->(inbound_email) { inbound_email.pending? } end - private - def route_later - ActionMailroom::RoutingJob.perform_later self - end + def route_later + ActionMailroom::RoutingJob.perform_later self + end end diff --git a/app/views/rails/conductor/action_mailroom/inbound_emails/show.html.erb b/app/views/rails/conductor/action_mailroom/inbound_emails/show.html.erb index e6f40b19e2..e761904196 100644 --- a/app/views/rails/conductor/action_mailroom/inbound_emails/show.html.erb +++ b/app/views/rails/conductor/action_mailroom/inbound_emails/show.html.erb @@ -3,7 +3,7 @@

<%= @inbound_email.message_id %>: <%= @inbound_email.status %>

@@ -11,3 +11,5 @@ Full email source
<%= @inbound_email.source %>
+ +<%= link_to "Back to all inbound emails", main_app.rails_conductor_inbound_emails_path %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 26151c338d..b44ddf648a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,5 +6,6 @@ Rails.application.routes.draw do # TODO: Should these be mounted within the engine only? scope "rails/conductor/action_mailroom/", module: "rails/conductor/action_mailroom" do resources :inbound_emails, as: :rails_conductor_inbound_emails + post ":inbound_email_id/reroute" => "reroutes#create", as: :rails_conductor_inbound_email_reroute end end