From d7cdd58db6b89711dcd38767093751aa09f19f79 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 14 Nov 2010 13:48:01 +0000 Subject: [PATCH] MailHandler: ignore assignee if invalid. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4404 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 5 ++++- .../fixtures/mail_handler/ticket_with_invalid_attributes.eml | 1 + test/unit/mail_handler_test.rb | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index a5cf21f97..00010059f 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -253,12 +253,15 @@ 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_user_from_keyword(k) + assigned_to = nil if assigned_to && !issue.assignable_users.include?(assigned_to) + { 'tracker_id' => ((k = get_keyword(:tracker)) && issue.project.trackers.find_by_name(k).try(:id)) || issue.project.trackers.find(:first).try(:id), 'status_id' => (k = get_keyword(:status)) && IssueStatus.find_by_name(k).try(:id), 'priority_id' => (k = get_keyword(:priority)) && IssuePriority.find_by_name(k).try(:id), 'category_id' => (k = get_keyword(:category)) && issue.project.issue_categories.find_by_name(k).try(:id), - 'assigned_to_id' => (k = get_keyword(:assigned_to, :override => true)) && find_user_from_keyword(k).try(:id), + 'assigned_to_id' => assigned_to.try(:id), 'fixed_version_id' => (k = get_keyword(:fixed_version, :override => true)) && issue.project.shared_versions.find_by_name(k).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}'), diff --git a/test/fixtures/mail_handler/ticket_with_invalid_attributes.eml b/test/fixtures/mail_handler/ticket_with_invalid_attributes.eml index 3b39fb551..4506078d7 100644 --- a/test/fixtures/mail_handler/ticket_with_invalid_attributes.eml +++ b/test/fixtures/mail_handler/ticket_with_invalid_attributes.eml @@ -40,6 +40,7 @@ pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. Project: onlinestore Tracker: Feature request category: Stock management +assigned to: miscuser9@foo.bar priority: foo done ratio: x start date: some day diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 65b0409bb..9fe35b62d 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -25,6 +25,7 @@ class MailHandlerTest < ActiveSupport::TestCase :roles, :members, :member_roles, + :users, :issues, :issue_statuses, :workflows, @@ -234,6 +235,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert issue.is_a?(Issue) assert !issue.new_record? issue.reload + assert_nil issue.assigned_to assert_nil issue.start_date assert_nil issue.due_date assert_equal 0, issue.done_ratio -- 2.39.5