mirror of
https://github.com/redmine/redmine.git
synced 2024-08-28 17:57:25 +02:00
Adds To and Cc as watchers when submitting an issue by email (#2245).
Only works if the sender has the 'Add issue watchers' permission. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2077 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
94899e0339
commit
84e70634fb
@ -92,7 +92,11 @@ class MailHandler < ActionMailer::Base
|
||||
issue.save!
|
||||
add_attachments(issue)
|
||||
logger.info "MailHandler: issue ##{issue.id} created by #{user}" if logger && logger.info
|
||||
# send notification before adding watchers since they were cc'ed
|
||||
Mailer.deliver_issue_add(issue) if Setting.notified_events.include?('issue_added')
|
||||
# add To and Cc as watchers
|
||||
add_watchers(issue)
|
||||
|
||||
issue
|
||||
end
|
||||
|
||||
@ -139,6 +143,18 @@ class MailHandler < ActionMailer::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Adds To and Cc as watchers of the given object if the sender has the
|
||||
# appropriate permission
|
||||
def add_watchers(obj)
|
||||
if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
|
||||
addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
|
||||
unless addresses.empty?
|
||||
watchers = User.find_active(:all, :conditions => ['LOWER(mail) IN (?)', addresses])
|
||||
watchers.each {|w| obj.add_watcher(w)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_keyword(attr)
|
||||
if @@handler_options[:allow_override].include?(attr.to_s) && email.plain_text_body =~ /^#{attr}:[ \t]*(.+)$/i
|
||||
$1.strip
|
||||
|
40
test/fixtures/mail_handler/ticket_with_cc.eml
vendored
Normal file
40
test/fixtures/mail_handler/ticket_with_cc.eml
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
Return-Path: <JSmith@somenet.foo>
|
||||
Received: from osiris ([127.0.0.1])
|
||||
by OSIRIS
|
||||
with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
|
||||
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
|
||||
From: "John Smith" <JSmith@somenet.foo>
|
||||
To: <redmine@somenet.foo>
|
||||
Cc: <DLopper@somenet.foo>
|
||||
Subject: New ticket on a given project
|
||||
Date: Sun, 22 Jun 2008 12:28:07 +0200
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain;
|
||||
format=flowed;
|
||||
charset="iso-8859-1";
|
||||
reply-type=original
|
||||
Content-Transfer-Encoding: 7bit
|
||||
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
|
||||
|
||||
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet
|
||||
turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus
|
||||
blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti
|
||||
sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In
|
||||
in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras
|
||||
sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum
|
||||
id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus
|
||||
eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique
|
||||
sed, mauris. Pellentesque habitant morbi tristique senectus et netus et
|
||||
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse
|
||||
platea dictumst.
|
||||
|
||||
Nulla et nunc. Duis pede. Donec et ipsum. Nam ut dui tincidunt neque
|
||||
sollicitudin iaculis. Duis vitae dolor. Vestibulum eget massa. Sed lorem.
|
||||
Nullam volutpat cursus erat. Cras felis dolor, lacinia quis, rutrum et,
|
||||
dictum et, ligula. Sed erat nibh, gravida in, accumsan non, placerat sed,
|
||||
massa. Sed sodales, ante fermentum ultricies sollicitudin, massa leo
|
||||
pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.
|
||||
|
@ -23,6 +23,8 @@ class MailHandlerTest < Test::Unit::TestCase
|
||||
:roles,
|
||||
:members,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:workflows,
|
||||
:trackers,
|
||||
:projects_trackers,
|
||||
:enumerations,
|
||||
@ -100,6 +102,15 @@ class MailHandlerTest < Test::Unit::TestCase
|
||||
assert_equal 10790, issue.attachments.first.filesize
|
||||
end
|
||||
|
||||
def test_add_issue_with_cc
|
||||
issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
|
||||
assert issue.is_a?(Issue)
|
||||
assert !issue.new_record?
|
||||
issue.reload
|
||||
assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
|
||||
assert_equal 1, issue.watchers.size
|
||||
end
|
||||
|
||||
def test_add_issue_note
|
||||
journal = submit_email('ticket_reply.eml')
|
||||
assert journal.is_a?(Journal)
|
||||
|
Loading…
Reference in New Issue
Block a user