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
This commit is contained in:
parent
080dc2212e
commit
e94c45d548
|
@ -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
|
||||
|
|
|
@ -53,3 +53,5 @@ Project: onlinestore
|
|||
Status: Resolved
|
||||
due date: 2010-12-31
|
||||
Start Date:2010-01-01
|
||||
Assigned to: John Smith
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue