Render anonymous and group avatars also when gravatar is disabled (#29824).

git-svn-id: https://svn.redmine.org/redmine/trunk@23940 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu
2025-09-06 22:11:58 +00:00
parent e06b4a8435
commit 81d647e34d
3 changed files with 11 additions and 8 deletions

View File

@@ -37,7 +37,14 @@ module AvatarsHelper
# Returns the avatar image tag for the given +user+ if avatars are enabled
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
def avatar(user, options = {})
if Setting.gravatar_enabled?
# "avatar" class should be added to all avatars
options[:class] = ['avatar', options[:class]].compact.join(' ')
if user.is_a?(AnonymousUser)
anonymous_avatar(options)
elsif user.is_a?(Group)
group_avatar(options)
elsif Setting.gravatar_enabled?
gravatar_avatar_tag(user, options)
elsif user.respond_to?(:initials)
initials_avatar_tag(user, options)
@@ -77,17 +84,13 @@ module AvatarsHelper
if email.present?
gravatar(email.to_s.downcase, options) rescue nil
elsif user.is_a?(AnonymousUser)
anonymous_avatar(options)
elsif user.is_a?(Group)
group_avatar(options)
end
end
def initials_avatar_tag(user, options)
size = (options.delete(:size) || GravatarHelper::DEFAULT_OPTIONS[:size]).to_i
css_class = ["avatar-color-#{user.id % 8}", 'avatar', "s#{size}", options[:class]].compact.join(' ')
css_class = ["avatar-color-#{user.id % 8}", "s#{size}", options[:class]].compact.join(' ')
content_tag('span', user.initials, role: 'img', class: css_class, title: options[:title])
end

View File

@@ -32,7 +32,7 @@ module GravatarHelper
:title => '',
# The class to assign to the img tag for the gravatar.
:class => 'gravatar avatar',
:class => 'gravatar',
}
# The methods that will be made available to your views.

View File

@@ -82,7 +82,7 @@ class AvatarsHelperTest < Redmine::HelperTest
def test_avatar_disabled_should_display_user_initials
with_settings :gravatar_enabled => '0' do
assert_equal "<span role=\"img\" class=\"avatar-color-2 avatar s24\">JS</span>", avatar(User.find_by_mail('jsmith@somenet.foo'))
assert_equal "<span role=\"img\" class=\"avatar-color-2 s24 avatar\">JS</span>", avatar(User.find_by_mail('jsmith@somenet.foo'))
end
end