diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index c664fd6dbe..41f76e5c4d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1482,6 +1482,10 @@ module ApplicationHelper
def avatar(user, options = { })
if Setting.gravatar_enabled?
options.merge!(:default => Setting.gravatar_default)
+ # style for HTML mail
+ if options.delete(:html_mail)
+ options[:style] = "#{options[:style]}width:14px;height:14px;border-radius:20%;vertical-align:middle;"
+ end
email = nil
if user.respond_to?(:mail)
email = user.mail
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index b49fe8983a..db3fe5eaa6 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -320,7 +320,11 @@ module IssuesHelper
%w(author status priority assigned_to category fixed_version start_date due_date).each do |attribute|
if issue.disabled_core_fields.grep(/^#{attribute}(_id)?$/).empty?
if html
- items << content_tag('strong', "#{l("field_#{attribute}")}: ") + (issue.send attribute)
+ value = issue.send(attribute)
+ if %w(author assigned_to).include?(attribute) && value.is_a?(User)
+ value = "#{avatar(value, :title => l("field_#{attribute}"), :html_mail => true)}#{value}".html_safe
+ end
+ items << content_tag('strong', "#{l("field_#{attribute}")}: ") + value
else
items << "#{l("field_#{attribute}")}: #{issue.send attribute}"
end
diff --git a/app/views/mailer/issue_add.html.erb b/app/views/mailer/issue_add.html.erb
index 7bb6115b59..28669bb3cf 100644
--- a/app/views/mailer/issue_add.html.erb
+++ b/app/views/mailer/issue_add.html.erb
@@ -1,3 +1,5 @@
-<%= l(:text_issue_added, :id => link_to("##{@issue.id}", @issue_url), :author => h(@issue.author)).html_safe %>
+<%= l(:text_issue_added,
+ :id => link_to("##{@issue.id}", @issue_url),
+ :author => "#{avatar(@issue.author, :html_mail => true)}#{h(@issue.author)}").html_safe %>
<%= render :partial => 'issue', :formats => [:html], :locals => { :issue => @issue, :user => @user, :issue_url => @issue_url } %>
diff --git a/app/views/mailer/issue_edit.html.erb b/app/views/mailer/issue_edit.html.erb
index b5bdd88eed..08088f9875 100644
--- a/app/views/mailer/issue_edit.html.erb
+++ b/app/views/mailer/issue_edit.html.erb
@@ -1,7 +1,9 @@
<% if @journal.private_notes? %>
(<%= l(:field_private_notes) %>)
<% end %>
-<%= l(:text_issue_updated, :id => link_to("##{@issue.id}", @issue_url), :author => h(@journal.user)).html_safe %>
+<%= l(:text_issue_updated,
+ :id => link_to("##{@issue.id}", @issue_url),
+ :author => "#{avatar(@journal.user, :html_mail => true)}#{h(@journal.user)}").html_safe %>
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index 1ae34a9f27..4cc94726c4 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -1505,6 +1505,14 @@ RAW
end
end
+ def test_avatar_with_html_mail_option
+ with_settings :gravatar_enabled => '1' do
+ avatar = avatar('jsmith ', :html_mail => true)
+ assert_include 'style="width:14px;height:14px;border-radius:20%;vertical-align:middle;"', avatar
+ assert_not_include 'html_mail', avatar
+ end
+ end
+
def test_avatar_disabled
with_settings :gravatar_enabled => '0' do
assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
diff --git a/test/unit/mailer_test.rb b/test/unit/mailer_test.rb
index 51fc001f9d..b6683f89c8 100644
--- a/test/unit/mailer_test.rb
+++ b/test/unit/mailer_test.rb
@@ -447,6 +447,35 @@ class MailerTest < ActiveSupport::TestCase
end
end
+ def test_issue_add_should_include_gravatar_if_gravatar_enabled
+ with_settings :gravatar_enabled => '1' do
+ issue = Issue.find(2)
+ Mailer.deliver_issue_add(issue)
+ gravatar_url = 'https://www.gravatar.com/avatar/'
+ option = '?rating=PG&size=50&default='
+ author_gravatar_url = gravatar_url + Digest::MD5.hexdigest(issue.author.mail) + option
+ assignee_gravatar_url = gravatar_url + Digest::MD5.hexdigest(issue.assigned_to.mail) + option
+
+ assert_select_email do
+ assert_select 'img[class=?]', 'gravatar', :count => 3
+ assert_select 'img[class="gravatar"][title=?][src=?]', '', author_gravatar_url, :count => 1
+ assert_select 'li img[class="gravatar"][title=?][src=?]', 'Author', author_gravatar_url, :count => 1
+ assert_select 'li img[class="gravatar"][title=?][src=?]', 'Assignee', assignee_gravatar_url, :count => 1
+ end
+ end
+ end
+
+ def test_issue_add_should_include_gravatar_if_gravatar_disabled
+ with_settings :gravatar_enabled => '0' do
+ issue = Issue.find(2)
+ Mailer.deliver_issue_add(issue)
+
+ assert_select_email do
+ assert_select 'img[class=?]', 'gravatar', :count => 0
+ end
+ end
+ end
+
def test_issue_edit_subject_should_include_status_changes_if_setting_is_enabled
with_settings :show_status_changes_in_mail_subject => 1 do
issue = Issue.find(2)
@@ -534,6 +563,36 @@ class MailerTest < ActiveSupport::TestCase
end
end
+ def test_issue_edit_should_include_gravatar_if_gravatar_enabled
+ with_settings :gravatar_enabled => '1' do
+ journal = Journal.find(3)
+ Mailer.deliver_issue_edit(journal)
+ gravatar_url = 'https://www.gravatar.com/avatar/'
+ option = '?rating=PG&size=50&default='
+ reported_user_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.user.mail) + option
+ author_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.issue.author.mail) + option
+ assignee_gravatar_url = gravatar_url + Digest::MD5.hexdigest(journal.issue.assigned_to.mail) + option
+
+ assert_select_email do
+ assert_select 'img[class="gravatar"]', :count => 3
+ assert_select 'img[class="gravatar"][title=?][src=?]', '', reported_user_gravatar_url, :count => 1
+ assert_select 'li img[class="gravatar"][title=?][src=?]', 'Author', author_gravatar_url, :count => 1
+ assert_select 'li img[class="gravatar"][title=?][src=?]', 'Assignee', assignee_gravatar_url, :count => 1
+ end
+ end
+ end
+
+ def test_issue_edit_should_include_gravatar_if_gravatar_disabled
+ with_settings :gravatar_enabled => '0' do
+ journal = Journal.find(3)
+ Mailer.deliver_issue_edit(journal)
+
+ assert_select_email do
+ assert_select 'img[class="gravatar"]', :count => 0
+ end
+ end
+ end
+
def test_version_file_added
attachements = [ Attachment.find_by_container_type('Version') ]
assert Mailer.deliver_attachments_added(attachements)