Adds a form to manually submit an email to the mail handler.

Use GET /mail_handler?key= to get the form.

git-svn-id: http://svn.redmine.org/redmine/trunk@14314 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2015-06-15 21:47:22 +00:00
parent 3ae42cb326
commit 95f7471e9c
5 changed files with 59 additions and 2 deletions

View File

@@ -18,6 +18,10 @@
class MailHandlerController < ActionController::Base class MailHandlerController < ActionController::Base
before_filter :check_credential before_filter :check_credential
# Displays the email submission form
def new
end
# Submits an incoming email to MailHandler # Submits an incoming email to MailHandler
def index def index
options = params.dup options = params.dup

View File

@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
label {display:block;margin:0.5em;}
</style>
</head>
<body>
<h1>Redmine Mail Handler</h1>
<%= form_tag({}, :multipart => true, :action => 'post') do %>
<%= hidden_field_tag 'key', params[:key] %>
<fieldset>
<legend>Raw Email</legend>
<%= text_area_tag 'email', '', :style => 'width:95%; height:400px;' %></label>
</fieldset>
<fieldset>
<legend>Options</legend>
<label>unknown_user: <%= select_tag 'unknown_user', options_for_select(['', 'ignore', 'accept', 'create']) %></label>
<label>default_group: <%= text_field_tag 'default_group' %></label>
<label>no_account_notice: <%= check_box_tag 'no_account_notice', 1 %></label>
<label>no_notification: <%= check_box_tag 'no_notification', 1 %></label>
<label>no_permission_check: <%= check_box_tag 'no_permission_check', 1 %></label>
</fieldset>
<fieldset>
<legend>Issue attributes options</legend>
<label>project: <%= text_field_tag 'issue[project]' %></label>
<label>status: <%= text_field_tag 'issue[status]' %></label>
<label>tracker: <%= text_field_tag 'issue[tracker]' %></label>
<label>category: <%= text_field_tag 'issue[category]' %></label>
<label>priority: <%= text_field_tag 'issue[priority]' %></label>
<label>private: <%= check_box_tag 'issue[private]', 1 %></label>
<label>allow_override: <%= text_field_tag 'allow_override' %></label>
</fieldset>
<p><%= submit_tag 'Submit Email' %></p>
<% end %>
</body>
</html>

View File

@@ -315,7 +315,9 @@ Rails.application.routes.draw do
get 'projects/:id/search', :controller => 'search', :action => 'index' get 'projects/:id/search', :controller => 'search', :action => 'index'
get 'search', :controller => 'search', :action => 'index' get 'search', :controller => 'search', :action => 'index'
match 'mail_handler', :controller => 'mail_handler', :action => 'index', :via => :post
get 'mail_handler', :to => 'mail_handler#new'
post 'mail_handler', :to => 'mail_handler#index'
match 'admin', :controller => 'admin', :action => 'index', :via => :get match 'admin', :controller => 'admin', :action => 'index', :via => :get
match 'admin/projects', :controller => 'admin', :action => 'projects', :via => :get match 'admin/projects', :controller => 'admin', :action => 'projects', :via => :get

View File

@@ -77,7 +77,6 @@ class MailHandlerControllerTest < ActionController::TestCase
end end
def test_should_not_allow_with_wrong_key def test_should_not_allow_with_wrong_key
# Disable API
Setting.mail_handler_api_enabled = 1 Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret' Setting.mail_handler_api_key = 'secret'
@@ -86,4 +85,12 @@ class MailHandlerControllerTest < ActionController::TestCase
end end
assert_response 403 assert_response 403
end end
def test_new
Setting.mail_handler_api_enabled = 1
Setting.mail_handler_api_key = 'secret'
get :new, :key => 'secret'
assert_response :success
end
end end

View File

@@ -19,6 +19,7 @@ require File.expand_path('../../../test_helper', __FILE__)
class RoutingMailHandlerTest < Redmine::RoutingTest class RoutingMailHandlerTest < Redmine::RoutingTest
def test_mail_handler def test_mail_handler
should_route 'GET /mail_handler' => 'mail_handler#new'
should_route 'POST /mail_handler' => 'mail_handler#index' should_route 'POST /mail_handler' => 'mail_handler#index'
end end
end end