From e94c45d5484138c500f040a917afaed13a47ddc8 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Sat, 29 May 2010 00:05:24 +0000 Subject: [PATCH] Add an "Assigned To" keyword to receiving email. #5594 Will take a user's email address, login, or full name. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3764 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 15 ++++++++++++++- .../mail_handler/ticket_on_given_project.eml | 2 ++ .../mail_handler/ticket_reply_with_status.eml | 1 + test/unit/mail_handler_test.rb | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 1b30af637..ae204b4f7 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -120,6 +120,7 @@ class MailHandler < ActionMailer::Base category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category))) priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority))) status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) + assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true))) due_date = get_keyword(:due_date, :override => true) start_date = get_keyword(:start_date, :override => true) @@ -128,7 +129,7 @@ class MailHandler < ActionMailer::Base raise UnauthorizedAction unless user.allowed_to?(:add_issues, project) end - issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :due_date => due_date, :start_date => start_date) + issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :due_date => due_date, :start_date => start_date, :assigned_to => assigned_to) # check workflow if status && issue.new_statuses_allowed_to(user).include?(status) issue.status = status @@ -167,6 +168,7 @@ class MailHandler < ActionMailer::Base status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) due_date = get_keyword(:due_date, :override => true) start_date = get_keyword(:start_date, :override => true) + assigned_to = (get_keyword(:assigned_to, :override => true) && find_user_from_keyword(get_keyword(:assigned_to, :override => true))) issue = Issue.find_by_id(issue_id) return unless issue @@ -185,6 +187,7 @@ class MailHandler < ActionMailer::Base end issue.start_date = start_date if start_date issue.due_date = due_date if due_date + issue.assigned_to = assigned_to if assigned_to issue.save! logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info @@ -320,4 +323,14 @@ class MailHandler < ActionMailer::Base end body.strip end + + def find_user_from_keyword(keyword) + user ||= User.find_by_mail(keyword) + user ||= User.find_by_login(keyword) + if user.nil? && keyword.match(/ /) + firstname, lastname = *(keyword.split) # "First Last Throwaway" + user ||= User.find_by_firstname_and_lastname(firstname, lastname) + end + user + end end diff --git a/test/fixtures/mail_handler/ticket_on_given_project.eml b/test/fixtures/mail_handler/ticket_on_given_project.eml index f62d9d63d..cfc90b534 100644 --- a/test/fixtures/mail_handler/ticket_on_given_project.eml +++ b/test/fixtures/mail_handler/ticket_on_given_project.eml @@ -53,3 +53,5 @@ Project: onlinestore Status: Resolved due date: 2010-12-31 Start Date:2010-01-01 +Assigned to: John Smith + diff --git a/test/fixtures/mail_handler/ticket_reply_with_status.eml b/test/fixtures/mail_handler/ticket_reply_with_status.eml index 90ed6d705..e7d68c3db 100644 --- a/test/fixtures/mail_handler/ticket_reply_with_status.eml +++ b/test/fixtures/mail_handler/ticket_reply_with_status.eml @@ -28,6 +28,7 @@ This is reply Status: Resolved due date: 2010-12-31 Start Date:2010-01-01 +Assigned to: jsmith@somenet.foo ------=_NextPart_000_0067_01C8D3CE.711F9CC0 Content-Type: text/html; diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index afc2029b8..29659daae 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -57,6 +57,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') assert_equal '2010-01-01', issue.start_date.to_s assert_equal '2010-12-31', issue.due_date.to_s + assert_equal User.find_by_login('jsmith'), issue.assigned_to # keywords should be removed from the email body assert !issue.description.match(/^Project:/i) assert !issue.description.match(/^Status:/i) @@ -256,6 +257,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal IssueStatus.find_by_name("Resolved"), issue.status assert_equal '2010-01-01', issue.start_date.to_s assert_equal '2010-12-31', issue.due_date.to_s + assert_equal User.find_by_login('jsmith'), issue.assigned_to end def test_add_issue_note_should_send_email_notification -- 2.39.5