Commit 05a37f69 authored by Jesse Hall's avatar Jesse Hall Committed by Lin Jen-Shin

Fix for #56295, https://gitlab.com/gitlab-org/gitlab-ce/issues/56295.

All avatars now visible in commit trailers.
parent 0fa2ea2e
......@@ -56,13 +56,13 @@ module AvatarsHelper
}))
end
def user_avatar_url_for(options = {})
def user_avatar_url_for(only_path: true, **options)
if options[:url]
options[:url]
elsif options[:user]
avatar_icon_for_user(options[:user], options[:size])
avatar_icon_for_user(options[:user], options[:size], only_path: only_path)
else
avatar_icon_for_email(options[:user_email], options[:size])
avatar_icon_for_email(options[:user_email], options[:size], only_path: only_path)
end
end
......@@ -75,6 +75,7 @@ module AvatarsHelper
has_tooltip = options[:has_tooltip].nil? ? true : options[:has_tooltip]
data_attributes = options[:data] || {}
css_class = %W[avatar s#{avatar_size}].push(*options[:css_class])
alt_text = user_name ? "#{user_name}'s avatar" : "default avatar"
if has_tooltip
css_class.push('has-tooltip')
......@@ -88,7 +89,7 @@ module AvatarsHelper
end
image_options = {
alt: "#{user_name}'s avatar",
alt: alt_text,
src: avatar_url,
data: data_attributes,
class: css_class,
......
---
title: Fix for missing avatar images dislpayed in commit trailers.
merge_request: 32374
author: Jesse Hall @jessehall3
type: fixed
......@@ -88,7 +88,8 @@ module Banzai
user: user,
user_email: email,
css_class: 'avatar-inline',
has_tooltip: false
has_tooltip: false,
only_path: false
)
link_href = user.nil? ? "mailto:#{email}" : urls.user_url(user)
......
......@@ -324,5 +324,47 @@ describe AvatarsHelper do
)
end
end
context 'with only_path parameter set to false' do
let(:user_with_avatar) { create(:user, :with_avatar, username: 'foobar') }
context 'with user parameter' do
let(:options) { { user: user_with_avatar, only_path: false } }
it 'will return avatar with a full path' do
is_expected.to eq tag(
:img,
alt: "#{user_with_avatar.name}'s avatar",
src: avatar_icon_for_user(user_with_avatar, 16, only_path: false),
data: { container: 'body' },
class: "avatar s16 has-tooltip",
title: user_with_avatar.name
)
end
end
context 'with user_name and user_email' do
let(:options) { { user_email: user_with_avatar.email, user_name: user_with_avatar.username, only_path: false } }
it 'will return avatar with a full path' do
is_expected.to eq tag(
:img,
alt: "#{user_with_avatar.username}'s avatar",
src: avatar_icon_for_email(user_with_avatar.email, 16, only_path: false),
data: { container: 'body' },
class: "avatar s16 has-tooltip",
title: user_with_avatar.username
)
end
end
end
context 'with unregistered email address' do
let(:options) { { user_email: "unregistered_email@example.com" } }
it 'will return default alt text for avatar' do
expect(subject).to include("default avatar")
end
end
end
end
......@@ -189,5 +189,26 @@ describe Banzai::Filter::CommitTrailersFilter do
expect_to_have_user_link_with_avatar(doc, user: user, trailer: trailer)
expect(doc.text).to include(commit_body)
end
context 'with Gitlab-hosted avatars in commit trailers' do
# Because commit trailers are contained within markdown,
# any path-only link will automatically be prefixed
# with the path of its repository.
# See: "build_relative_path" in "lib/banzai/filter/relative_link_filter.rb"
let(:user_with_avatar) { create(:user, :with_avatar, username: 'foobar') }
it 'returns a full path for avatar urls' do
_, message_html = build_commit_message(
trailer: trailer,
name: user_with_avatar.name,
email: user_with_avatar.email
)
doc = filter(message_html)
expected = "#{Gitlab.config.gitlab.url}#{user_with_avatar.avatar_url}"
expect(doc.css('img')[0].attr('src')).to start_with expected
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment