##// END OF EJS Templates
Add watchers from To and Cc fields in issue replies (#7017)....
Jean-Philippe Lang -
r14710:91da86a688c2
parent child
Show More
@@ -0,0 +1,19
1 Return-Path: <JSmith@somenet.foo>
2 Received: from osiris ([127.0.0.1])
3 by OSIRIS
4 with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
5 Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
6 In-Reply-To: <redmine.issue-2.20060719210421@osiris>
7 From: "John Smith" <JSmith@somenet.foo>
8 To: <redmine@somenet.foo>
9 Cc: <dlopper@somenet.foo>
10 Subject: Re: update to issue 2
11 Date: Sun, 22 Jun 2008 12:28:07 +0200
12 MIME-Version: 1.0
13 Content-Type: text/plain;
14 format=flowed;
15 charset="iso-8859-1";
16 reply-type=original
17 Content-Transfer-Encoding: 7bit
18
19 An update to the issue by the sender.
@@ -240,6 +240,9 class MailHandler < ActionMailer::Base
240 issue.safe_attributes = issue_attributes_from_keywords(issue)
240 issue.safe_attributes = issue_attributes_from_keywords(issue)
241 issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
241 issue.safe_attributes = {'custom_field_values' => custom_field_values_from_keywords(issue)}
242 journal.notes = cleaned_up_text_body
242 journal.notes = cleaned_up_text_body
243
244 # add To and Cc as watchers before saving so the watchers can reply to Redmine
245 add_watchers(issue)
243 add_attachments(issue)
246 add_attachments(issue)
244 issue.save!
247 issue.save!
245 if logger
248 if logger
@@ -314,8 +317,10 class MailHandler < ActionMailer::Base
314 if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
317 if user.allowed_to?("add_#{obj.class.name.underscore}_watchers".to_sym, obj.project)
315 addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
318 addresses = [email.to, email.cc].flatten.compact.uniq.collect {|a| a.strip.downcase}
316 unless addresses.empty?
319 unless addresses.empty?
317 User.active.having_mail(addresses).each do |w|
320 users = User.active.having_mail(addresses).to_a
318 obj.add_watcher(w)
321 users -= obj.watcher_users
322 users.each do |u|
323 obj.add_watcher(u)
319 end
324 end
320 end
325 end
321 end
326 end
@@ -265,7 +265,7 class MailHandlerTest < ActiveSupport::TestCase
265 end
265 end
266 end
266 end
267
267
268 def test_add_issue_with_cc
268 def test_add_issue_should_add_cc_as_watchers
269 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
269 issue = submit_email('ticket_with_cc.eml', :issue => {:project => 'ecookbook'})
270 assert issue.is_a?(Issue)
270 assert issue.is_a?(Issue)
271 assert !issue.new_record?
271 assert !issue.new_record?
@@ -813,6 +813,28 class MailHandlerTest < ActiveSupport::TestCase
813 assert_equal 'Normal', journal.issue.priority.name
813 assert_equal 'Normal', journal.issue.priority.name
814 end
814 end
815
815
816 def test_update_issue_should_add_cc_as_watchers
817 Watcher.delete_all
818 issue = Issue.find(2)
819
820 assert_difference 'Watcher.count' do
821 assert submit_email('issue_update_with_cc.eml')
822 end
823 issue.reload
824 assert_equal 1, issue.watcher_user_ids.size
825 assert issue.watched_by?(User.find_by_mail('dlopper@somenet.foo'))
826 end
827
828 def test_update_issue_should_not_add_cc_as_watchers_if_already_watching
829 Watcher.delete_all
830 issue = Issue.find(2)
831 Watcher.create!(:watchable => issue, :user => User.find_by_mail('dlopper@somenet.foo'))
832
833 assert_no_difference 'Watcher.count' do
834 assert submit_email('issue_update_with_cc.eml')
835 end
836 end
837
816 def test_replying_to_a_private_note_should_add_reply_as_private
838 def test_replying_to_a_private_note_should_add_reply_as_private
817 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
839 private_journal = Journal.create!(:notes => 'Private notes', :journalized => Issue.find(1), :private_notes => true, :user_id => 2)
818
840
General Comments 0
You need to be logged in to leave comments. Login now