Use the default project when receiving an email with an invalid project keyword (#14491).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12067 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-07-29 16:37:45 +00:00
parent 27c3299f32
commit 1502da5726
2 changed files with 17 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class MailHandler < ActionMailer::Base
@@handler_options = options.dup @@handler_options = options.dup
@@handler_options[:issue] ||= {} @@handler_options[:issue] ||= {}
@@handler_options[:issue].symbolize_keys!
if @@handler_options[:allow_override].is_a?(String) if @@handler_options[:allow_override].is_a?(String)
@@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip)
@ -333,6 +334,13 @@ class MailHandler < ActionMailer::Base
# * parse the email To field # * parse the email To field
# * specific project (eg. Setting.mail_handler_target_project) # * specific project (eg. Setting.mail_handler_target_project)
target = Project.find_by_identifier(get_keyword(:project)) target = Project.find_by_identifier(get_keyword(:project))
if target.nil?
# Invalid project keyword, use the project specified as the default one
default_project = @@handler_options[:issue][:project]
if default_project.present?
target = Project.find_by_identifier(default_project)
end
end
raise MissingInformation.new('Unable to determine target project') if target.nil? raise MissingInformation.new('Unable to determine target project') if target.nil?
target target
end end

View File

@ -370,6 +370,15 @@ class MailHandlerTest < ActiveSupport::TestCase
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
end end
def test_add_issue_with_invalid_project_should_be_assigned_to_default_project
issue = submit_email('ticket_on_given_project.eml', :issue => {:project => 'ecookbook'}, :allow_override => 'project') do |email|
email.gsub!(/^Project:.+$/, 'Project: invalid')
end
assert issue.is_a?(Issue)
assert !issue.new_record?
assert_equal 'ecookbook', issue.project.identifier
end
def test_add_issue_with_localized_attributes def test_add_issue_with_localized_attributes
User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr' User.find_by_mail('jsmith@somenet.foo').update_attribute 'language', 'fr'
issue = submit_email( issue = submit_email(