]> source.dussan.org Git - redmine.git/commitdiff
Adds an option to send email on "Assignee updated" in application settings (#16362).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2014 08:19:45 +0000 (08:19 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 17 Mar 2014 08:19:45 +0000 (08:19 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@12974 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/journal.rb
lib/redmine/notifiable.rb
test/unit/journal_observer_test.rb
test/unit/lib/redmine/notifiable_test.rb

index 10ebf8ee6a23fe834b2be83ea5dc7d4688cf2553..5d10ef83f1fabf2f305f1cd10c92c97d72a2e545 100644 (file)
@@ -80,15 +80,20 @@ class Journal < ActiveRecord::Base
     end
   end
 
+  # Returns the JournalDetail for the given attribute, or nil if the attribute
+  # was not updated
+  def detail_for_attribute(attribute)
+    details.detect {|detail| detail.prop_key == attribute}
+  end
+
   # Returns the new status if the journal contains a status change, otherwise nil
   def new_status
-    c = details.detect {|detail| detail.prop_key == 'status_id'}
-    (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
+    s = new_value_for('status_id')
+    s ? IssueStatus.find_by_id(s.to_i) : nil
   end
 
   def new_value_for(prop)
-    c = details.detect {|detail| detail.prop_key == prop}
-    c ? c.value : nil
+    detail_for_attribute(prop).try(:value)
   end
 
   def editable_by?(usr)
@@ -185,6 +190,7 @@ class Journal < ActiveRecord::Base
     if notify? && (Setting.notified_events.include?('issue_updated') ||
         (Setting.notified_events.include?('issue_note_added') && notes.present?) ||
         (Setting.notified_events.include?('issue_status_updated') && new_status.present?) ||
+        (Setting.notified_events.include?('issue_assigned_to_updated') && new_value_for('assigned_to_id').present?) ||
         (Setting.notified_events.include?('issue_priority_updated') && new_value_for('priority_id').present?)
       )
       Mailer.deliver_issue_edit(self)
index 88ca9d7762a648fd530c0ded34c311ef14c82f63..41fd736e6aef96aaabf2793492770f9124c451d5 100644 (file)
@@ -12,6 +12,7 @@ module Redmine
       notifications << Notifiable.new('issue_updated')
       notifications << Notifiable.new('issue_note_added', 'issue_updated')
       notifications << Notifiable.new('issue_status_updated', 'issue_updated')
+      notifications << Notifiable.new('issue_assigned_to_updated', 'issue_updated')
       notifications << Notifiable.new('issue_priority_updated', 'issue_updated')
       notifications << Notifiable.new('news_added')
       notifications << Notifiable.new('news_comment_added')
index 50c76028e8e88e624ef0ef519598d5a4e9505089..eabd2779dd3a6836a43158eb02d31795d9c46ef4 100644 (file)
@@ -87,7 +87,6 @@ class JournalObserverTest < ActiveSupport::TestCase
     assert_equal 0, ActionMailer::Base.deliveries.size
   end
 
-  # context: issue_status_updated notified_events
   def test_create_should_send_email_notification_with_issue_status_updated
     issue = Issue.first
     user = User.first
@@ -112,7 +111,44 @@ class JournalObserverTest < ActiveSupport::TestCase
     assert_equal 0, ActionMailer::Base.deliveries.size
   end
 
-  # context: issue_priority_updated notified_events
+  def test_create_without_status_update_should_not_send_email_notification_with_issue_status_updated
+    issue = Issue.first
+    user = User.first
+    issue.init_journal(user, issue)
+    issue.subject = "No status update"
+
+    with_settings :notified_events => %w(issue_status_updated) do
+      assert issue.save
+    end
+    assert_equal 0, ActionMailer::Base.deliveries.size
+  end
+
+  def test_create_should_send_email_notification_with_issue_assignee_updated
+    issue = Issue.generate!(:assigned_to_id => 2)
+    ActionMailer::Base.deliveries.clear
+    user = User.first
+    issue.init_journal(user, issue)
+    issue.assigned_to = User.find(3)
+
+    with_settings :notified_events => %w(issue_assigned_to_updated) do
+      assert issue.save
+    end
+    assert_equal 1, ActionMailer::Base.deliveries.size
+  end
+
+  def test_create_should_not_send_email_notification_without_issue_assignee_updated
+    issue = Issue.generate!(:assigned_to_id => 2)
+    ActionMailer::Base.deliveries.clear
+    user = User.first
+    issue.init_journal(user, issue)
+    issue.assigned_to = User.find(3)
+
+    with_settings :notified_events => [] do
+      assert issue.save
+    end
+    assert_equal 0, ActionMailer::Base.deliveries.size
+  end
+
   def test_create_should_send_email_notification_with_issue_priority_updated
     issue = Issue.first
     user = User.first
index f1d9149c775575be5ddaafbb629981f655197005..18e4de04e1597dc8635504cf51375de2f083a50e 100644 (file)
@@ -24,7 +24,7 @@ class Redmine::NotifiableTest < ActiveSupport::TestCase
   def test_all
     assert_equal 12, Redmine::Notifiable.all.length
 
-    %w(issue_added issue_updated issue_note_added issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
+    %w(issue_added issue_updated issue_note_added issue_status_updated issue_status_updated issue_priority_updated news_added news_comment_added document_added file_added message_posted wiki_content_added wiki_content_updated).each do |notifiable|
       assert Redmine::Notifiable.all.collect(&:name).include?(notifiable), "missing #{notifiable}"
     end
   end