From b1e08b468b7041ef5df179213f686722b0ead358 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Sep 2018 16:45:59 -0700 Subject: [PATCH] Provide a basic admin interface BEHOLD THE CONDUCTOR! --- .../inbound_emails_controller.rb | 27 +++++++++++++++++-- .../inbound_emails/index.html.erb | 15 +++++++++++ .../inbound_emails/new.html.erb | 8 ++++++ .../inbound_emails/show.html.erb | 8 ++++++ app/views/layouts/action_mailroom.html.erb | 7 +++++ config/routes.rb | 4 +-- 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 app/views/action_mailroom/inbound_emails/index.html.erb create mode 100644 app/views/action_mailroom/inbound_emails/new.html.erb create mode 100644 app/views/action_mailroom/inbound_emails/show.html.erb create mode 100644 app/views/layouts/action_mailroom.html.erb diff --git a/app/controllers/action_mailroom/inbound_emails_controller.rb b/app/controllers/action_mailroom/inbound_emails_controller.rb index cf44367b7b..b8fa6cde49 100644 --- a/app/controllers/action_mailroom/inbound_emails_controller.rb +++ b/app/controllers/action_mailroom/inbound_emails_controller.rb @@ -2,15 +2,38 @@ # TODO: Spam/malware catching? # TODO: Specific bounces for SMTP good citizenship: 200/404/400 class ActionMailroom::InboundEmailsController < ActionController::Base + layout "action_mailroom" + skip_forgery_protection - before_action :require_rfc822_message + before_action :ensure_development_env, except: :create + before_action :require_rfc822_message, only: :create + + def index + @inbound_emails = ActionMailroom::InboundEmail.order(created_at: :desc) + end + + def new + end + + def show + @inbound_email = ActionMailroom::InboundEmail.find(params[:id]) + end def create ActionMailroom::InboundEmail.create_from_raw_email!(params[:message]) - head :created + + respond_to do |format| + format.html { redirect_to main_app.rails_new_inbound_email_url } + format.any { head :created } + end end private + # TODO: Should probably separate the admin interface and do more to ensure that it isn't exposed to the web + def ensure_development_env + head :forbidden unless Rails.env.development? + end + def require_rfc822_message head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822' end diff --git a/app/views/action_mailroom/inbound_emails/index.html.erb b/app/views/action_mailroom/inbound_emails/index.html.erb new file mode 100644 index 0000000000..6636e351be --- /dev/null +++ b/app/views/action_mailroom/inbound_emails/index.html.erb @@ -0,0 +1,15 @@ +<% provide :title, "Deliver new inbound email" %> + +

All inbound emails

+ + + + <% @inbound_emails.each do |inbound_email| %> + + + + + <% end %> +
Message IDStatus
<%= link_to inbound_email.message_id, main_app.rails_inbound_email_path(inbound_email) %><%= inbound_email.status %>
+ +<%= link_to "Deliver new inbound email", main_app.new_rails_inbound_email_path %> \ No newline at end of file diff --git a/app/views/action_mailroom/inbound_emails/new.html.erb b/app/views/action_mailroom/inbound_emails/new.html.erb new file mode 100644 index 0000000000..dfd0bd7ea5 --- /dev/null +++ b/app/views/action_mailroom/inbound_emails/new.html.erb @@ -0,0 +1,8 @@ +<% provide :title, "Deliver new inbound email" %> + +

Deliver new inbound email

+ +<%= form_with(url: main_app.rails_inbound_emails_url, remote: false) do |form| %> + <%= form.file_field :message, size: "150x50", autofocus: true %>
+ <%= form.submit "Deliver inbound email" %> +<% end %> diff --git a/app/views/action_mailroom/inbound_emails/show.html.erb b/app/views/action_mailroom/inbound_emails/show.html.erb new file mode 100644 index 0000000000..bc443775e4 --- /dev/null +++ b/app/views/action_mailroom/inbound_emails/show.html.erb @@ -0,0 +1,8 @@ +<% provide :title, @inbound_email.message_id %> + +

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

+ + diff --git a/app/views/layouts/action_mailroom.html.erb b/app/views/layouts/action_mailroom.html.erb new file mode 100644 index 0000000000..3efa8c3989 --- /dev/null +++ b/app/views/layouts/action_mailroom.html.erb @@ -0,0 +1,7 @@ + + + <%= yield :title %> + + +<%= yield %> + diff --git a/config/routes.rb b/config/routes.rb index a24d5054cf..e19c641a68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Rails.application.routes.draw do - scope "rails/action_mailroom" do - post "/inbound_emails" => "action_mailroom/inbound_emails#create", as: :rails_inbound_emails + scope 'rails/action_mailroom', module: 'action_mailroom' do + resources :inbound_emails, as: :rails_inbound_emails end end