1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-10-17 17:01:01 +00:00

Mail handler: no attributes overridable by default (#20543).

git-svn-id: http://svn.redmine.org/redmine/trunk@14680 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2015-10-17 08:00:16 +00:00
parent b68b5819d5
commit af3c91d02a
2 changed files with 21 additions and 20 deletions

View File

@ -33,10 +33,9 @@ class MailHandler < ActionMailer::Base
options[:allow_override] = options[:allow_override].split(',').collect(&:strip)
end
options[:allow_override] ||= []
options[:allow_override].map!(&:downcase)
# Project needs to be overridable if not specified
options[:allow_override] << 'project' unless options[:issue].has_key?(:project)
# Status overridable by default
options[:allow_override] << 'status' unless options[:issue].has_key?(:status)
options[:no_account_notice] = (options[:no_account_notice].to_s == '1')
options[:no_notification] = (options[:no_notification].to_s == '1')
@ -328,7 +327,7 @@ class MailHandler < ActionMailer::Base
@keywords[attr]
else
@keywords[attr] = begin
if (options[:override] || handler_options[:allow_override].include?(attr.to_s)) &&
if (options[:override] || handler_options[:allow_override].include?(attr.to_s.downcase)) &&
(v = extract_keyword!(cleaned_up_text_body, attr, options[:format]))
v
elsif !handler_options[:issue][attr].blank?
@ -380,20 +379,17 @@ class MailHandler < ActionMailer::Base
# Returns a Hash of issue attributes extracted from keywords in the email body
def issue_attributes_from_keywords(issue)
assigned_to = (k = get_keyword(:assigned_to, :override => true)) && find_assignee_from_keyword(k, issue)
attrs = {
'tracker_id' => (k = get_keyword(:tracker)) && issue.project.trackers.named(k).first.try(:id),
'status_id' => (k = get_keyword(:status)) && IssueStatus.named(k).first.try(:id),
'priority_id' => (k = get_keyword(:priority)) && IssuePriority.named(k).first.try(:id),
'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.named(k).first.try(:id),
'assigned_to_id' => assigned_to.try(:id),
'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) &&
issue.project.shared_versions.named(k).first.try(:id),
'start_date' => get_keyword(:start_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
'due_date' => get_keyword(:due_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
'estimated_hours' => get_keyword(:estimated_hours, :override => true),
'done_ratio' => get_keyword(:done_ratio, :override => true, :format => '(\d|10)?0')
'assigned_to_id' => (k = get_keyword(:assigned_to)) && find_assignee_from_keyword(k, issue).try(:id),
'fixed_version_id' => (k = get_keyword(:fixed_version)) && issue.project.shared_versions.named(k).first.try(:id),
'start_date' => get_keyword(:start_date, :format => '\d{4}-\d{2}-\d{2}'),
'due_date' => get_keyword(:due_date, :format => '\d{4}-\d{2}-\d{2}'),
'estimated_hours' => get_keyword(:estimated_hours),
'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0')
}.delete_if {|k, v| v.blank? }
if issue.new_record? && attrs['tracker_id'].nil?
@ -406,7 +402,7 @@ class MailHandler < ActionMailer::Base
# Returns a Hash of issue custom field values extracted from keywords in the email body
def custom_field_values_from_keywords(customized)
customized.custom_field_values.inject({}) do |h, v|
if keyword = get_keyword(v.custom_field.name, :override => true)
if keyword = get_keyword(v.custom_field.name)
h[v.custom_field.id.to_s] = v.custom_field.value_from_keyword(keyword, customized)
end
h

View File

@ -44,7 +44,9 @@ class MailHandlerTest < ActiveSupport::TestCase
ActionMailer::Base.deliveries.clear
lft1 = new_issue_lft
# This email contains: 'Project: onlinestore'
issue = submit_email('ticket_on_given_project.eml')
issue = submit_email('ticket_on_given_project.eml',
:allow_override => ['status', 'start_date', 'due_date', 'assigned_to', 'fixed_version', 'estimated_hours', 'done_ratio']
)
assert issue.is_a?(Issue)
assert !issue.new_record?
issue.reload
@ -120,7 +122,7 @@ class MailHandlerTest < ActiveSupport::TestCase
def test_add_issue_with_group_assignment
with_settings :issue_group_assignment => '1' do
issue = submit_email('ticket_on_given_project.eml') do |email|
issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
end
assert issue.is_a?(Issue)
@ -182,7 +184,9 @@ class MailHandlerTest < ActiveSupport::TestCase
end
def test_add_issue_with_custom_fields
issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
issue = submit_email('ticket_with_custom_fields.eml',
:issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable field']
)
assert issue.is_a?(Issue)
assert !issue.new_record?
issue.reload
@ -195,7 +199,9 @@ class MailHandlerTest < ActiveSupport::TestCase
def test_add_issue_with_version_custom_fields
field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'ecookbook'}) do |email|
issue = submit_email('ticket_with_custom_fields.eml',
:issue => {:project => 'ecookbook'}, :allow_override => ['affected version']
) do |email|
email << "Affected version: 1.0\n"
end
assert issue.is_a?(Issue)
@ -207,7 +213,7 @@ class MailHandlerTest < ActiveSupport::TestCase
def test_add_issue_should_match_assignee_on_display_name
user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
User.add_to_project(user, Project.find(2))
issue = submit_email('ticket_on_given_project.eml') do |email|
issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
end
assert issue.is_a?(Issue)
@ -707,8 +713,7 @@ class MailHandlerTest < ActiveSupport::TestCase
end
def test_update_issue_with_attribute_changes
# This email contains: 'Status: Resolved'
journal = submit_email('ticket_reply_with_status.eml')
journal = submit_email('ticket_reply_with_status.eml', :allow_override => ['status','assigned_to','start_date','due_date', 'float field'])
assert journal.is_a?(Journal)
issue = Issue.find(journal.issue.id)
assert_equal User.find_by_login('jsmith'), journal.user