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