Add 'Start date' and 'End date' keywords for incoming email. #5595

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3763 e93f8b46-1217-0410-a6f0-8f06a7374b81
pull/351/head
Eric Davis 15 years ago
parent af726ea8f0
commit 080dc2212e
  1. 13
      app/models/mail_handler.rb
  2. 3
      test/fixtures/mail_handler/ticket_on_given_project.eml
  3. 3
      test/fixtures/mail_handler/ticket_reply_with_status.eml
  4. 6
      test/unit/mail_handler_test.rb

@ -120,13 +120,15 @@ class MailHandler < ActionMailer::Base
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category))) category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority))) priority = (get_keyword(:priority) && IssuePriority.find_by_name(get_keyword(:priority)))
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) 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)
# check permission # check permission
unless @@handler_options[:no_permission_check] unless @@handler_options[:no_permission_check]
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project) raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
end end
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority) issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :due_date => due_date, :start_date => start_date)
# check workflow # check workflow
if status && issue.new_statuses_allowed_to(user).include?(status) if status && issue.new_statuses_allowed_to(user).include?(status)
issue.status = status issue.status = status
@ -163,6 +165,8 @@ class MailHandler < ActionMailer::Base
# Adds a note to an existing issue # Adds a note to an existing issue
def receive_issue_reply(issue_id) def receive_issue_reply(issue_id)
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) 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)
issue = Issue.find_by_id(issue_id) issue = Issue.find_by_id(issue_id)
return unless issue return unless issue
@ -179,6 +183,9 @@ class MailHandler < ActionMailer::Base
if status && issue.new_statuses_allowed_to(user).include?(status) if status && issue.new_statuses_allowed_to(user).include?(status)
issue.status = status issue.status = status
end end
issue.start_date = start_date if start_date
issue.due_date = due_date if due_date
issue.save! issue.save!
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
journal journal
@ -245,7 +252,7 @@ class MailHandler < ActionMailer::Base
@keywords[attr] @keywords[attr]
else else
@keywords[attr] = begin @keywords[attr] = begin
if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr}[ \t]*:[ \t]*(.+)\s*$/i, '') if (options[:override] || @@handler_options[:allow_override].include?(attr.to_s)) && plain_text_body.gsub!(/^#{attr.to_s.humanize}[ \t]*:[ \t]*(.+)\s*$/i, '')
$1.strip $1.strip
elsif !@@handler_options[:issue][attr].blank? elsif !@@handler_options[:issue][attr].blank?
@@handler_options[:issue][attr] @@handler_options[:issue][attr]

@ -51,4 +51,5 @@ pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
Project: onlinestore Project: onlinestore
Status: Resolved Status: Resolved
due date: 2010-12-31
Start Date:2010-01-01

@ -26,6 +26,9 @@ Content-Transfer-Encoding: quoted-printable
This is reply This is reply
Status: Resolved Status: Resolved
due date: 2010-12-31
Start Date:2010-01-01
------=_NextPart_000_0067_01C8D3CE.711F9CC0 ------=_NextPart_000_0067_01C8D3CE.711F9CC0
Content-Type: text/html; Content-Type: text/html;
charset="utf-8" charset="utf-8"

@ -55,6 +55,8 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal Project.find(2), issue.project assert_equal Project.find(2), issue.project
assert_equal IssueStatus.find_by_name('Resolved'), issue.status assert_equal IssueStatus.find_by_name('Resolved'), issue.status
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.') 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
# keywords should be removed from the email body # keywords should be removed from the email body
assert !issue.description.match(/^Project:/i) assert !issue.description.match(/^Project:/i)
assert !issue.description.match(/^Status:/i) assert !issue.description.match(/^Status:/i)
@ -243,7 +245,7 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_match /This is reply/, journal.notes assert_match /This is reply/, journal.notes
end end
def test_add_issue_note_with_status_change def test_add_issue_note_with_attribute_changes
# This email contains: 'Status: Resolved' # This email contains: 'Status: Resolved'
journal = submit_email('ticket_reply_with_status.eml') journal = submit_email('ticket_reply_with_status.eml')
assert journal.is_a?(Journal) assert journal.is_a?(Journal)
@ -252,6 +254,8 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal Issue.find(2), journal.journalized assert_equal Issue.find(2), journal.journalized
assert_match /This is reply/, journal.notes assert_match /This is reply/, journal.notes
assert_equal IssueStatus.find_by_name("Resolved"), issue.status 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
end end
def test_add_issue_note_should_send_email_notification def test_add_issue_note_should_send_email_notification

Loading…
Cancel
Save