Patch #1669 ยป mail_handler-add-status-keyword.patch
| test/unit/mail_handler_test.rb (working copy) | ||
|---|---|---|
| 45 | 45 |
assert_equal Project.find(2), issue.project |
| 46 | 46 |
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
| 47 | 47 |
end |
| 48 | ||
| 49 |
def test_add_issue_with_status |
|
| 50 |
# This email contains: 'Project: onlinestore' and 'Status: Resolved' |
|
| 51 |
issue = submit_email('ticket_on_given_project.eml')
|
|
| 52 |
assert issue.is_a?(Issue) |
|
| 53 |
assert !issue.new_record? |
|
| 54 |
issue.reload |
|
| 55 |
assert_equal Project.find(2), issue.project |
|
| 56 |
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
|
| 57 |
end |
|
| 48 | 58 |
|
| 49 | 59 |
def test_add_issue_with_attributes_override |
| 50 | 60 |
issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
|
| ... | ... | |
| 95 | 105 |
assert journal.is_a?(Journal) |
| 96 | 106 |
assert_equal User.find_by_login('jsmith'), journal.user
|
| 97 | 107 |
assert_equal Issue.find(2), journal.journalized |
| 98 |
assert_equal 'This is reply', journal.notes
|
|
| 108 |
assert_match /This is reply/, journal.notes
|
|
| 99 | 109 |
end |
| 100 | 110 | |
| 111 |
def test_add_issue_note_with_status_change |
|
| 112 |
# This email contains: 'Status: Resolved' |
|
| 113 |
journal = submit_email('ticket_reply_with_status.eml')
|
|
| 114 |
assert journal.is_a?(Journal) |
|
| 115 |
issue = Issue.find(journal.issue.id) |
|
| 116 |
assert_equal User.find_by_login('jsmith'), journal.user
|
|
| 117 |
assert_equal Issue.find(2), journal.journalized |
|
| 118 |
assert_match /This is reply/, journal.notes |
|
| 119 |
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
|
| 120 |
end |
|
| 121 | ||
| 101 | 122 |
private |
| 102 | 123 |
|
| 103 | 124 |
def submit_email(filename, options={})
|
| test/fixtures/mail_handler/ticket_reply_with_status.eml (revision 0) | ||
|---|---|---|
| 1 |
Return-Path: <jsmith@somenet.foo> |
|
| 2 |
Received: from osiris ([127.0.0.1]) |
|
| 3 |
by OSIRIS |
|
| 4 |
with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200 |
|
| 5 |
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris> |
|
| 6 |
From: "John Smith" <jsmith@somenet.foo> |
|
| 7 |
To: <redmine@somenet.foo> |
|
| 8 |
References: <485d0ad366c88_d7014663a025f@osiris.tmail> |
|
| 9 |
Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories |
|
| 10 |
Date: Sat, 21 Jun 2008 18:41:39 +0200 |
|
| 11 |
MIME-Version: 1.0 |
|
| 12 |
Content-Type: multipart/alternative; |
|
| 13 |
boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0" |
|
| 14 |
X-Priority: 3 |
|
| 15 |
X-MSMail-Priority: Normal |
|
| 16 |
X-Mailer: Microsoft Outlook Express 6.00.2900.2869 |
|
| 17 |
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 |
|
| 18 | ||
| 19 |
This is a multi-part message in MIME format. |
|
| 20 | ||
| 21 |
------=_NextPart_000_0067_01C8D3CE.711F9CC0 |
|
| 22 |
Content-Type: text/plain; |
|
| 23 |
charset="utf-8" |
|
| 24 |
Content-Transfer-Encoding: quoted-printable |
|
| 25 | ||
| 26 |
This is reply |
|
| 27 | ||
| 28 |
Status: Resolved |
|
| 29 |
------=_NextPart_000_0067_01C8D3CE.711F9CC0 |
|
| 30 |
Content-Type: text/html; |
|
| 31 |
charset="utf-8" |
|
| 32 |
Content-Transfer-Encoding: quoted-printable |
|
| 33 | ||
| 34 |
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
|
| 35 |
<HTML><HEAD> |
|
| 36 |
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"> |
|
| 37 |
<STYLE>BODY {
|
|
| 38 |
FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif |
|
| 39 |
} |
|
| 40 |
BODY H1 {
|
|
| 41 |
FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, = |
|
| 42 |
sans-serif |
|
| 43 |
} |
|
| 44 |
A {
|
|
| 45 |
COLOR: #2a5685 |
|
| 46 |
} |
|
| 47 |
A:link {
|
|
| 48 |
COLOR: #2a5685 |
|
| 49 |
} |
|
| 50 |
A:visited {
|
|
| 51 |
COLOR: #2a5685 |
|
| 52 |
} |
|
| 53 |
A:hover {
|
|
| 54 |
COLOR: #c61a1a |
|
| 55 |
} |
|
| 56 |
A:active {
|
|
| 57 |
COLOR: #c61a1a |
|
| 58 |
} |
|
| 59 |
HR {
|
|
| 60 |
BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; = |
|
| 61 |
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px |
|
| 62 |
} |
|
| 63 |
.footer {
|
|
| 64 |
FONT-SIZE: 0.8em; FONT-STYLE: italic |
|
| 65 |
} |
|
| 66 |
</STYLE> |
|
| 67 | ||
| 68 |
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD> |
|
| 69 |
<BODY bgColor=3D#ffffff> |
|
| 70 |
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 = |
|
| 71 |
size=3D2>This is=20 |
|
| 72 |
reply Status: Resolved</FONT></DIV></SPAN></BODY></HTML> |
|
| 73 | ||
| 74 |
------=_NextPart_000_0067_01C8D3CE.711F9CC0-- |
|
| 75 | ||
| test/fixtures/mail_handler/ticket_on_given_project.eml (working copy) | ||
|---|---|---|
| 38 | 38 |
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus. |
| 39 | 39 |
|
| 40 | 40 |
Project: onlinestore |
| 41 |
Status: Resolved |
|
| 41 | 42 |
|
| app/models/mail_handler.rb (working copy) | ||
|---|---|---|
| 31 | 31 |
@@handler_options[:allow_override] ||= [] |
| 32 | 32 |
# Project needs to be overridable if not specified |
| 33 | 33 |
@@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project) |
| 34 |
# Status needs to be overridable if not specified |
|
| 35 |
@@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status) |
|
| 34 | 36 |
super email |
| 35 | 37 |
end |
| 36 | 38 |
|
| ... | ... | |
| 76 | 78 |
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first) |
| 77 | 79 |
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category))) |
| 78 | 80 |
priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
|
| 81 |
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) || IssueStatus.default |
|
| 79 | 82 | |
| 80 | 83 |
# check permission |
| 81 | 84 |
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project) |
| 82 |
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority) |
|
| 85 |
issue = Issue.new(:author => user, :project => project, :tracker => tracker, :category => category, :priority => priority, :status => status)
|
|
| 83 | 86 |
issue.subject = email.subject.chomp |
| 84 | 87 |
issue.description = email.plain_text_body.chomp |
| 85 | 88 |
issue.save! |
| ... | ... | |
| 100 | 103 |
|
| 101 | 104 |
# Adds a note to an existing issue |
| 102 | 105 |
def receive_issue_update(issue_id) |
| 106 |
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) |
|
| 107 |
|
|
| 103 | 108 |
issue = Issue.find_by_id(issue_id) |
| 104 | 109 |
return unless issue |
| 105 | 110 |
# check permission |
| 106 | 111 |
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project) |
| 112 |
raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project) |
|
| 113 | ||
| 107 | 114 |
# add the note |
| 108 | 115 |
journal = issue.init_journal(user, email.plain_text_body.chomp) |
| 109 | 116 |
add_attachments(issue) |
| 117 |
issue.status = status unless status.nil? |
|
| 110 | 118 |
issue.save! |
| 111 | 119 |
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
| 112 | 120 |
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|