Commit b4c158e1 authored by Nick Thomas's avatar Nick Thomas

Merge branch...

Merge branch '300874-follow-up-from-trying-to-open-ci-cd-settings-on-gitlab-project-fails-with-500' into 'master'

Add generic avatar method for users and groups

See merge request gitlab-org/gitlab!59758
parents 32e3873b 762901c9
......@@ -98,6 +98,14 @@ module AvatarsHelper
end
end
def avatar_without_link(resource, options = {})
if resource.is_a?(User)
user_avatar_without_link(options.merge(user: resource))
elsif resource.is_a?(Group)
group_icon(resource, options.merge(class: 'avatar'))
end
end
private
def avatar_icon_by_user_email_or_gravatar(email, size, scale, only_path:)
......@@ -136,9 +144,10 @@ module AvatarsHelper
def source_identicon(source, options = {})
bg_key = (source.id % 7) + 1
size_class = "s#{options[:size]}" if options[:size]
options[:class] =
[*options[:class], "identicon bg#{bg_key}"].join(' ')
[*options[:class], "identicon bg#{bg_key}", size_class].compact.join(' ')
content_tag(:div, class: options[:class].strip) do
source.name[0, 1].upcase
......
---
title: Add generic avatar method for users and groups
merge_request: 59758
author:
type: fixed
......@@ -19,7 +19,7 @@
%thead
%tr
%th= _("Project")
%th= _("Author")
%th= _("Owner")
%th
%tbody
- @project.upstream_project_subscriptions.each do |subscription|
......
......@@ -3,8 +3,9 @@
%td
= project.name
%td
= user_avatar_without_link(user: project.owner, size: 32)
= project.owner.name
.gl-display-flex.gl-align-items-center
= avatar_without_link(project.owner, size: 32)
= project.owner.name
%td.gl-text-right
= link_to project_subscription_path(@project, subscription.id), method: :delete, data: { toggle: 'tooltip', title: tooltip, container: 'body', testid: 'delete-subscription' }, class: "gl-button btn btn-danger" do
= sprite_icon('close', size: 16, css_class: 'gl-icon')
......@@ -409,4 +409,33 @@ RSpec.describe AvatarsHelper do
end
end
end
describe '#avatar_without_link' do
let(:options) { { size: 32 } }
subject { helper.avatar_without_link(resource, options) }
context 'with users' do
let(:resource) { user }
it 'displays user avatar' do
is_expected.to eq tag(
:img,
alt: "#{user.name}'s avatar",
src: avatar_icon_for_user(user, 32),
data: { container: 'body' },
class: 'avatar s32 has-tooltip',
title: user.name
)
end
end
context 'with groups' do
let(:resource) { build_stubbed(:group, name: 'foo') }
it 'displays group avatar' do
is_expected.to match(%r{<div class="avatar identicon bg\d+ s32">F</div>})
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