]> source.dussan.org Git - redmine.git/commitdiff
X-Redmine-Issue-Assignee email header field is empty when the assignee of an issue...
authorGo MAEDA <maeda@farend.jp>
Tue, 18 May 2021 05:18:23 +0000 (05:18 +0000)
committerGo MAEDA <maeda@farend.jp>
Tue, 18 May 2021 05:18:23 +0000 (05:18 +0000)
Patch by Akihiro MATOBA.

git-svn-id: http://svn.redmine.org/redmine/trunk@21005 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mailer.rb
test/unit/mailer_test.rb

index f58a1c88df610148ceccf45f64cbf7363856e51c..c095b796cc1fab5d05724cff6fa68db599d2300a 100644 (file)
@@ -74,8 +74,8 @@ class Mailer < ActionMailer::Base
     redmine_headers 'Project' => issue.project.identifier,
                     'Issue-Tracker' => issue.tracker.name,
                     'Issue-Id' => issue.id,
-                    'Issue-Author' => issue.author.login
-    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
+                    'Issue-Author' => issue.author.login,
+                    'Issue-Assignee' => assignee_for_header(issue)
     message_id issue
     references issue
     @author = issue.author
@@ -106,8 +106,8 @@ class Mailer < ActionMailer::Base
     redmine_headers 'Project' => issue.project.identifier,
                     'Issue-Tracker' => issue.tracker.name,
                     'Issue-Id' => issue.id,
-                    'Issue-Author' => issue.author.login
-    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
+                    'Issue-Author' => issue.author.login,
+                    'Issue-Assignee' => assignee_for_header(issue)
     message_id journal
     references issue
     @author = journal.user
@@ -760,7 +760,16 @@ class Mailer < ActionMailer::Base
 
   # Appends a Redmine header field (name is prepended with 'X-Redmine-')
   def redmine_headers(h)
-    h.each {|k, v| headers["X-Redmine-#{k}"] = v.to_s}
+    h.compact.each {|k, v| headers["X-Redmine-#{k}"] = v.to_s}
+  end
+
+  def assignee_for_header(issue)
+    case issue.assigned_to
+    when User
+      issue.assigned_to.login
+    when Group
+      "Group (#{issue.assigned_to.name})"
+    end
   end
 
   # Singleton class method is public
index b25e174270085e243316994878aab6a1db55d353..da12788f837eb61ab40f61d5e899c94efc804421 100644 (file)
@@ -219,6 +219,33 @@ class MailerTest < ActiveSupport::TestCase
     assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
   end
 
+  def test_email_headers_should_not_include_assignee_when_not_assigned
+    issue = Issue.find(6)
+    issue.init_journal(User.current)
+    issue.update(:status_id => 4)
+    issue.update(:assigned_to_id => nil)
+    mail = last_email
+    assert_not mail.header['X-Redmine-Issue-Assignee']
+  end
+
+  def test_email_headers_should_include_assignee_when_assigned
+    issue = Issue.find(6)
+    issue.init_journal(User.current)
+    issue.update(:assigned_to_id => 2)
+    mail = last_email
+    assert_equal 'jsmith', mail.header['X-Redmine-Issue-Assignee'].to_s
+  end
+
+  def test_email_headers_should_include_assignee_if_assigned_to_group
+    issue = Issue.find(6)
+    with_settings :issue_group_assignment => 1 do
+      issue.init_journal(User.current)
+      issue.update(:assigned_to_id => 10)
+    end
+    mail = last_email
+    assert_equal 'Group (A Team)', mail.header['X-Redmine-Issue-Assignee'].to_s
+  end
+
   def test_plain_text_mail
     Setting.plain_text_mail = 1
     journal = Journal.find(2)