35017_v2.patch

Go MAEDA, 2021-05-16 08:53

Download (3.06 KB)

View differences:

app/models/mailer.rb
74 74
    redmine_headers 'Project' => issue.project.identifier,
75 75
                    'Issue-Tracker' => issue.tracker.name,
76 76
                    'Issue-Id' => issue.id,
77
                    'Issue-Author' => issue.author.login
78
    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
77
                    'Issue-Author' => issue.author.login,
78
                    'Issue-Assignee' => assignee_for_redmine_header(issue)
79 79
    message_id issue
80 80
    references issue
81 81
    @author = issue.author
......
106 106
    redmine_headers 'Project' => issue.project.identifier,
107 107
                    'Issue-Tracker' => issue.tracker.name,
108 108
                    'Issue-Id' => issue.id,
109
                    'Issue-Author' => issue.author.login
110
    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
109
                    'Issue-Author' => issue.author.login,
110
                    'Issue-Assignee' => assignee_for_redmine_header(issue)
111 111
    message_id journal
112 112
    references issue
113 113
    @author = journal.user
......
760 760

  
761 761
  # Appends a Redmine header field (name is prepended with 'X-Redmine-')
762 762
  def redmine_headers(h)
763
    h.each {|k, v| headers["X-Redmine-#{k}"] = v.to_s}
763
    h.compact.each {|k, v| headers["X-Redmine-#{k}"] = v.to_s}
764
  end
765

  
766
  def assignee_for_redmine_header(issue)
767
    case issue&.assigned_to
768
    when User
769
      issue.assigned_to.login
770
    when Group
771
      "Group (#{issue.assigned_to.name})"
772
    end
764 773
  end
765 774

  
766 775
  # Singleton class method is public
test/unit/mailer_test.rb
219 219
    assert_equal issue.author.login, mail.header['X-Redmine-Sender'].to_s
220 220
  end
221 221

  
222
  def test_email_headers_should_not_include_assignee_when_not_assigned
223
    issue = Issue.find(6)
224
    issue.init_journal(User.current)
225
    issue.update(:status_id => 4)
226
    issue.update(:assigned_to_id => nil)
227
    mail = last_email
228
    assert_not mail.header['X-Redmine-Issue-Assignee']
229
  end
230

  
231
  def test_email_headers_should_include_assignee_when_assigned
232
    issue = Issue.find(6)
233
    issue.init_journal(User.current)
234
    issue.update(:assigned_to_id => 2)
235
    mail = last_email
236
    assert_equal 'jsmith', mail.header['X-Redmine-Issue-Assignee'].to_s
237
  end
238

  
239
  def test_email_headers_should_include_assignee_if_assigned_to_group
240
    issue = Issue.find(6)
241
    with_settings :issue_group_assignment => 1 do
242
      issue.init_journal(User.current)
243
      issue.update(:assigned_to_id => 10)
244
    end
245
    mail = last_email
246
    assert_equal 'Group (A Team)', mail.header['X-Redmine-Issue-Assignee'].to_s
247
  end
248

  
222 249
  def test_plain_text_mail
223 250
    Setting.plain_text_mail = 1
224 251
    journal = Journal.find(2)