##// END OF EJS Templates
Mail handler: no attributes overridable by default (#20543)....
Jean-Philippe Lang -
r14298:af3c91d02aff
parent child
Show More
@@ -33,10 +33,9 class MailHandler < ActionMailer::Base
33 33 options[:allow_override] = options[:allow_override].split(',').collect(&:strip)
34 34 end
35 35 options[:allow_override] ||= []
36 options[:allow_override].map!(&:downcase)
36 37 # Project needs to be overridable if not specified
37 38 options[:allow_override] << 'project' unless options[:issue].has_key?(:project)
38 # Status overridable by default
39 options[:allow_override] << 'status' unless options[:issue].has_key?(:status)
40 39
41 40 options[:no_account_notice] = (options[:no_account_notice].to_s == '1')
42 41 options[:no_notification] = (options[:no_notification].to_s == '1')
@@ -328,7 +327,7 class MailHandler < ActionMailer::Base
328 327 @keywords[attr]
329 328 else
330 329 @keywords[attr] = begin
331 if (options[:override] || handler_options[:allow_override].include?(attr.to_s)) &&
330 if (options[:override] || handler_options[:allow_override].include?(attr.to_s.downcase)) &&
332 331 (v = extract_keyword!(cleaned_up_text_body, attr, options[:format]))
333 332 v
334 333 elsif !handler_options[:issue][attr].blank?
@@ -380,20 +379,17 class MailHandler < ActionMailer::Base
380 379
381 380 # Returns a Hash of issue attributes extracted from keywords in the email body
382 381 def issue_attributes_from_keywords(issue)
383 assigned_to = (k = get_keyword(:assigned_to, :override => true)) && find_assignee_from_keyword(k, issue)
384
385 382 attrs = {
386 383 'tracker_id' => (k = get_keyword(:tracker)) && issue.project.trackers.named(k).first.try(:id),
387 384 'status_id' => (k = get_keyword(:status)) && IssueStatus.named(k).first.try(:id),
388 385 'priority_id' => (k = get_keyword(:priority)) && IssuePriority.named(k).first.try(:id),
389 386 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.named(k).first.try(:id),
390 'assigned_to_id' => assigned_to.try(:id),
391 'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) &&
392 issue.project.shared_versions.named(k).first.try(:id),
393 'start_date' => get_keyword(:start_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
394 'due_date' => get_keyword(:due_date, :override => true, :format => '\d{4}-\d{2}-\d{2}'),
395 'estimated_hours' => get_keyword(:estimated_hours, :override => true),
396 'done_ratio' => get_keyword(:done_ratio, :override => true, :format => '(\d|10)?0')
387 'assigned_to_id' => (k = get_keyword(:assigned_to)) && find_assignee_from_keyword(k, issue).try(:id),
388 'fixed_version_id' => (k = get_keyword(:fixed_version)) && issue.project.shared_versions.named(k).first.try(:id),
389 'start_date' => get_keyword(:start_date, :format => '\d{4}-\d{2}-\d{2}'),
390 'due_date' => get_keyword(:due_date, :format => '\d{4}-\d{2}-\d{2}'),
391 'estimated_hours' => get_keyword(:estimated_hours),
392 'done_ratio' => get_keyword(:done_ratio, :format => '(\d|10)?0')
397 393 }.delete_if {|k, v| v.blank? }
398 394
399 395 if issue.new_record? && attrs['tracker_id'].nil?
@@ -406,7 +402,7 class MailHandler < ActionMailer::Base
406 402 # Returns a Hash of issue custom field values extracted from keywords in the email body
407 403 def custom_field_values_from_keywords(customized)
408 404 customized.custom_field_values.inject({}) do |h, v|
409 if keyword = get_keyword(v.custom_field.name, :override => true)
405 if keyword = get_keyword(v.custom_field.name)
410 406 h[v.custom_field.id.to_s] = v.custom_field.value_from_keyword(keyword, customized)
411 407 end
412 408 h
@@ -44,7 +44,9 class MailHandlerTest < ActiveSupport::TestCase
44 44 ActionMailer::Base.deliveries.clear
45 45 lft1 = new_issue_lft
46 46 # This email contains: 'Project: onlinestore'
47 issue = submit_email('ticket_on_given_project.eml')
47 issue = submit_email('ticket_on_given_project.eml',
48 :allow_override => ['status', 'start_date', 'due_date', 'assigned_to', 'fixed_version', 'estimated_hours', 'done_ratio']
49 )
48 50 assert issue.is_a?(Issue)
49 51 assert !issue.new_record?
50 52 issue.reload
@@ -120,7 +122,7 class MailHandlerTest < ActiveSupport::TestCase
120 122
121 123 def test_add_issue_with_group_assignment
122 124 with_settings :issue_group_assignment => '1' do
123 issue = submit_email('ticket_on_given_project.eml') do |email|
125 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
124 126 email.gsub!('Assigned to: John Smith', 'Assigned to: B Team')
125 127 end
126 128 assert issue.is_a?(Issue)
@@ -182,7 +184,9 class MailHandlerTest < ActiveSupport::TestCase
182 184 end
183 185
184 186 def test_add_issue_with_custom_fields
185 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'onlinestore'})
187 issue = submit_email('ticket_with_custom_fields.eml',
188 :issue => {:project => 'onlinestore'}, :allow_override => ['database', 'Searchable field']
189 )
186 190 assert issue.is_a?(Issue)
187 191 assert !issue.new_record?
188 192 issue.reload
@@ -195,7 +199,9 class MailHandlerTest < ActiveSupport::TestCase
195 199 def test_add_issue_with_version_custom_fields
196 200 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1,2,3])
197 201
198 issue = submit_email('ticket_with_custom_fields.eml', :issue => {:project => 'ecookbook'}) do |email|
202 issue = submit_email('ticket_with_custom_fields.eml',
203 :issue => {:project => 'ecookbook'}, :allow_override => ['affected version']
204 ) do |email|
199 205 email << "Affected version: 1.0\n"
200 206 end
201 207 assert issue.is_a?(Issue)
@@ -207,7 +213,7 class MailHandlerTest < ActiveSupport::TestCase
207 213 def test_add_issue_should_match_assignee_on_display_name
208 214 user = User.generate!(:firstname => 'Foo Bar', :lastname => 'Foo Baz')
209 215 User.add_to_project(user, Project.find(2))
210 issue = submit_email('ticket_on_given_project.eml') do |email|
216 issue = submit_email('ticket_on_given_project.eml', :allow_override => ['assigned_to']) do |email|
211 217 email.sub!(/^Assigned to.*$/, 'Assigned to: Foo Bar Foo baz')
212 218 end
213 219 assert issue.is_a?(Issue)
@@ -707,8 +713,7 class MailHandlerTest < ActiveSupport::TestCase
707 713 end
708 714
709 715 def test_update_issue_with_attribute_changes
710 # This email contains: 'Status: Resolved'
711 journal = submit_email('ticket_reply_with_status.eml')
716 journal = submit_email('ticket_reply_with_status.eml', :allow_override => ['status','assigned_to','start_date','due_date', 'float field'])
712 717 assert journal.is_a?(Journal)
713 718 issue = Issue.find(journal.issue.id)
714 719 assert_equal User.find_by_login('jsmith'), journal.user
General Comments 0
You need to be logged in to leave comments. Login now