1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Provide a basic admin interface

BEHOLD THE CONDUCTOR!
This commit is contained in:
David Heinemeier Hansson 2018-09-27 16:45:59 -07:00
parent 4f0d6c87b1
commit b1e08b468b
6 changed files with 65 additions and 4 deletions

View file

@ -2,15 +2,38 @@
# TODO: Spam/malware catching? # TODO: Spam/malware catching?
# TODO: Specific bounces for SMTP good citizenship: 200/404/400 # TODO: Specific bounces for SMTP good citizenship: 200/404/400
class ActionMailroom::InboundEmailsController < ActionController::Base class ActionMailroom::InboundEmailsController < ActionController::Base
layout "action_mailroom"
skip_forgery_protection 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 def create
ActionMailroom::InboundEmail.create_from_raw_email!(params[:message]) 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 end
private 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 def require_rfc822_message
head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822' head :unsupported_media_type unless params.require(:message).content_type == 'message/rfc822'
end end

View file

@ -0,0 +1,15 @@
<% provide :title, "Deliver new inbound email" %>
<h1>All inbound emails</h1>
<table>
<tr><th>Message ID</th><th>Status</th></tr>
<% @inbound_emails.each do |inbound_email| %>
<tr>
<td><%= link_to inbound_email.message_id, main_app.rails_inbound_email_path(inbound_email) %></td>
<td><%= inbound_email.status %></td>
</tr>
<% end %>
</table>
<%= link_to "Deliver new inbound email", main_app.new_rails_inbound_email_path %>

View file

@ -0,0 +1,8 @@
<% provide :title, "Deliver new inbound email" %>
<h1>Deliver new inbound email</h1>
<%= form_with(url: main_app.rails_inbound_emails_url, remote: false) do |form| %>
<%= form.file_field :message, size: "150x50", autofocus: true %><br>
<%= form.submit "Deliver inbound email" %>
<% end %>

View file

@ -0,0 +1,8 @@
<% provide :title, @inbound_email.message_id %>
<h1><%= @inbound_email.message_id %>: <%= @inbound_email.status %></h1>
<ul>
<li>Retry</li>
<li>Incinerate</li>
</ul>

View file

@ -0,0 +1,7 @@
<html>
<head>
<title><%= yield :title %></title>
</head>
<body>
<%= yield %>
</html>

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
scope "rails/action_mailroom" do scope 'rails/action_mailroom', module: 'action_mailroom' do
post "/inbound_emails" => "action_mailroom/inbound_emails#create", as: :rails_inbound_emails resources :inbound_emails, as: :rails_inbound_emails
end end
end end