Patch #1669 ยป mail_handler-add-status-keyword.patch
| test/unit/mail_handler_test.rb (working copy) | ||
|---|---|---|
|
assert_equal Project.find(2), issue.project
|
||
|
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
|
||
|
end
|
||
|
def test_add_issue_with_status
|
||
|
# This email contains: 'Project: onlinestore' and 'Status: Resolved'
|
||
|
issue = submit_email('ticket_on_given_project.eml')
|
||
|
assert issue.is_a?(Issue)
|
||
|
assert !issue.new_record?
|
||
|
issue.reload
|
||
|
assert_equal Project.find(2), issue.project
|
||
|
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
||
|
end
|
||
|
|
||
|
def test_add_issue_with_attributes_override
|
||
|
issue = submit_email('ticket_with_attributes.eml', :allow_override => 'tracker,category,priority')
|
||
| ... | ... | |
|
assert journal.is_a?(Journal)
|
||
|
assert_equal User.find_by_login('jsmith'), journal.user
|
||
|
assert_equal Issue.find(2), journal.journalized
|
||
|
assert_equal 'This is reply', journal.notes
|
||
|
assert_match /This is reply/, journal.notes
|
||
|
end
|
||
|
def test_add_issue_note_with_status_change
|
||
|
# This email contains: 'Status: Resolved'
|
||
|
journal = submit_email('ticket_reply_with_status.eml')
|
||
|
assert journal.is_a?(Journal)
|
||
|
issue = Issue.find(journal.issue.id)
|
||
|
assert_equal User.find_by_login('jsmith'), journal.user
|
||
|
assert_equal Issue.find(2), journal.journalized
|
||
|
assert_match /This is reply/, journal.notes
|
||
|
assert_equal IssueStatus.find_by_name("Resolved"), issue.status
|
||
|
end
|
||
|
private
|
||
|
|
||
|
def submit_email(filename, options={})
|
||
| test/fixtures/mail_handler/ticket_reply_with_status.eml (revision 0) | ||
|---|---|---|
|
Return-Path: <jsmith@somenet.foo>
|
||
|
Received: from osiris ([127.0.0.1])
|
||
|
by OSIRIS
|
||
|
with hMailServer ; Sat, 21 Jun 2008 18:41:39 +0200
|
||
|
Message-ID: <006a01c8d3bd$ad9baec0$0a00a8c0@osiris>
|
||
|
From: "John Smith" <jsmith@somenet.foo>
|
||
|
To: <redmine@somenet.foo>
|
||
|
References: <485d0ad366c88_d7014663a025f@osiris.tmail>
|
||
|
Subject: Re: [Cookbook - Feature #2] (New) Add ingredients categories
|
||
|
Date: Sat, 21 Jun 2008 18:41:39 +0200
|
||
|
MIME-Version: 1.0
|
||
|
Content-Type: multipart/alternative;
|
||
|
boundary="----=_NextPart_000_0067_01C8D3CE.711F9CC0"
|
||
|
X-Priority: 3
|
||
|
X-MSMail-Priority: Normal
|
||
|
X-Mailer: Microsoft Outlook Express 6.00.2900.2869
|
||
|
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
|
||
|
This is a multi-part message in MIME format.
|
||
|
------=_NextPart_000_0067_01C8D3CE.711F9CC0
|
||
|
Content-Type: text/plain;
|
||
|
charset="utf-8"
|
||
|
Content-Transfer-Encoding: quoted-printable
|
||
|
This is reply
|
||
|
Status: Resolved
|
||
|
------=_NextPart_000_0067_01C8D3CE.711F9CC0
|
||
|
Content-Type: text/html;
|
||
|
charset="utf-8"
|
||
|
Content-Transfer-Encoding: quoted-printable
|
||
|
=EF=BB=BF<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
|
<HTML><HEAD>
|
||
|
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8">
|
||
|
<STYLE>BODY {
|
||
|
FONT-SIZE: 0.8em; COLOR: #484848; FONT-FAMILY: Verdana, sans-serif
|
||
|
}
|
||
|
BODY H1 {
|
||
|
FONT-SIZE: 1.2em; MARGIN: 0px; FONT-FAMILY: "Trebuchet MS", Verdana, =
|
||
|
sans-serif
|
||
|
}
|
||
|
A {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:link {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:visited {
|
||
|
COLOR: #2a5685
|
||
|
}
|
||
|
A:hover {
|
||
|
COLOR: #c61a1a
|
||
|
}
|
||
|
A:active {
|
||
|
COLOR: #c61a1a
|
||
|
}
|
||
|
HR {
|
||
|
BORDER-RIGHT: 0px; BORDER-TOP: 0px; BACKGROUND: #ccc; BORDER-LEFT: 0px; =
|
||
|
WIDTH: 100%; BORDER-BOTTOM: 0px; HEIGHT: 1px
|
||
|
}
|
||
|
.footer {
|
||
|
FONT-SIZE: 0.8em; FONT-STYLE: italic
|
||
|
}
|
||
|
</STYLE>
|
||
|
<META content=3D"MSHTML 6.00.2900.2883" name=3DGENERATOR></HEAD>
|
||
|
<BODY bgColor=3D#ffffff>
|
||
|
<DIV><SPAN class=3Dfooter><FONT face=3DArial color=3D#000000 =
|
||
|
size=3D2>This is=20
|
||
|
reply Status: Resolved</FONT></DIV></SPAN></BODY></HTML>
|
||
|
------=_NextPart_000_0067_01C8D3CE.711F9CC0--
|
||
| test/fixtures/mail_handler/ticket_on_given_project.eml (working copy) | ||
|---|---|---|
|
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
|
||
|
|
||
|
Project: onlinestore
|
||
|
Status: Resolved
|
||
|
|
||
| app/models/mail_handler.rb (working copy) | ||
|---|---|---|
|
@@handler_options[:allow_override] ||= []
|
||
|
# Project needs to be overridable if not specified
|
||
|
@@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project)
|
||
|
# Status needs to be overridable if not specified
|
||
|
@@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
|
||
|
super email
|
||
|
end
|
||
|
|
||
| ... | ... | |
|
tracker = (get_keyword(:tracker) && project.trackers.find_by_name(get_keyword(:tracker))) || project.trackers.find(:first)
|
||
|
category = (get_keyword(:category) && project.issue_categories.find_by_name(get_keyword(:category)))
|
||
|
priority = (get_keyword(:priority) && Enumeration.find_by_opt_and_name('IPRI', get_keyword(:priority)))
|
||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status))) || IssueStatus.default
|
||
|
# check permission
|
||
|
raise UnauthorizedAction unless user.allowed_to?(:add_issues, project)
|
||
|
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, :status => status)
|
||
|
issue.subject = email.subject.chomp
|
||
|
issue.description = email.plain_text_body.chomp
|
||
|
issue.save!
|
||
| ... | ... | |
|
|
||
|
# Adds a note to an existing issue
|
||
|
def receive_issue_update(issue_id)
|
||
|
status = (get_keyword(:status) && IssueStatus.find_by_name(get_keyword(:status)))
|
||
|
|
||
|
issue = Issue.find_by_id(issue_id)
|
||
|
return unless issue
|
||
|
# check permission
|
||
|
raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project)
|
||
|
raise UnauthorizedAction unless status.nil? || user.allowed_to?(:edit_issues, issue.project)
|
||
|
# add the note
|
||
|
journal = issue.init_journal(user, email.plain_text_body.chomp)
|
||
|
add_attachments(issue)
|
||
|
issue.status = status unless status.nil?
|
||
|
issue.save!
|
||
|
logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info
|
||
|
Mailer.deliver_issue_edit(journal) if Setting.notified_events.include?('issue_updated')
|
||