diff options
author | Stan Hu <stanhu@gmail.com> | 2018-09-28 06:58:30 -0400 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-09-28 07:39:58 -0400 |
commit | b49e6b419acb3e8c129398167ec6b521fc686f8d (patch) | |
tree | 3b9256856b8becc0218b1055f19d637950ed0fd7 | |
parent | 790eabcaf4a703d2776a0c6e0c461d35598e37b1 (diff) | |
download | gitlab-ce-sh-fix-forks-with-no-gravatar.tar.gz |
Fix Error 500 when forking projects with Gravatar disabledsh-fix-forks-with-no-gravatar
When Gravatar is disabled, the "no avatar" is used, which failed
to revert to the colorful identity icons for namespaces.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/50254
-rw-r--r-- | app/helpers/avatars_helper.rb | 21 | ||||
-rw-r--r-- | app/views/projects/edit.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/forks/_fork_button.html.haml | 4 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-forks-with-no-gravatar.yml | 5 | ||||
-rw-r--r-- | spec/features/projects/fork_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/avatars_helper_spec.rb | 24 |
6 files changed, 28 insertions, 40 deletions
diff --git a/app/helpers/avatars_helper.rb b/app/helpers/avatars_helper.rb index 321811a3ca3..7fc4c1a023f 100644 --- a/app/helpers/avatars_helper.rb +++ b/app/helpers/avatars_helper.rb @@ -1,12 +1,12 @@ # frozen_string_literal: true module AvatarsHelper - def project_icon(project_id, options = {}) - source_icon(Project, project_id, options) + def project_icon(project, options = {}) + source_icon(project, options) end - def group_icon(group_id, options = {}) - source_icon(Group, group_id, options) + def group_icon(group, options = {}) + source_icon(group, options) end # Takes both user and email and returns the avatar_icon by @@ -110,16 +110,11 @@ module AvatarsHelper private - def source_icon(klass, source_id, options = {}) - source = - if source_id.respond_to?(:avatar_url) - source_id - else - klass.find_by_full_path(source_id) - end + def source_icon(source, options = {}) + avatar_url = source.try(:avatar_url) - if source.avatar_url - image_tag source.avatar_url, options + if avatar_url + image_tag avatar_url, options else source_identicon(source, options) end diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml index bfd165d8ba5..07fc9e1c682 100644 --- a/app/views/projects/edit.html.haml +++ b/app/views/projects/edit.html.haml @@ -47,7 +47,7 @@ .form-group - if @project.avatar? .avatar-container.s160.append-bottom-15 - = project_icon(@project.full_path, alt: '', class: 'avatar project-avatar s160', width: 160, height: 160) + = project_icon(@project, alt: '', class: 'avatar project-avatar s160', width: 160, height: 160) - if @project.avatar_in_git %p.light = _("Project avatar in repository: %{link}").html_safe % { link: @project.avatar_in_git } diff --git a/app/views/projects/forks/_fork_button.html.haml b/app/views/projects/forks/_fork_button.html.haml index 12cf40bb65f..a69146513d8 100644 --- a/app/views/projects/forks/_fork_button.html.haml +++ b/app/views/projects/forks/_fork_button.html.haml @@ -5,7 +5,7 @@ .bordered-box.fork-thumbnail.text-center.prepend-left-default.append-right-default.prepend-top-default.append-bottom-default.forked = link_to project_path(forked_project) do - if /no_((\w*)_)*avatar/.match(avatar) - = project_icon(namespace, class: "avatar s100 identicon") + = group_icon(namespace, class: "avatar s100 identicon") - else .avatar-container.s100 = image_tag(avatar, class: "avatar s100") @@ -18,7 +18,7 @@ class: ("disabled has-tooltip" unless can_create_project), title: (_('You have reached your project limit') unless can_create_project) do - if /no_((\w*)_)*avatar/.match(avatar) - = project_icon(namespace, class: "avatar s100 identicon") + = group_icon(namespace, class: "avatar s100 identicon") - else .avatar-container.s100 = image_tag(avatar, class: "avatar s100") diff --git a/changelogs/unreleased/sh-fix-forks-with-no-gravatar.yml b/changelogs/unreleased/sh-fix-forks-with-no-gravatar.yml new file mode 100644 index 00000000000..f18e6207b87 --- /dev/null +++ b/changelogs/unreleased/sh-fix-forks-with-no-gravatar.yml @@ -0,0 +1,5 @@ +--- +title: Fix Error 500 when forking projects with Gravatar disabled +merge_request: +author: +type: fixed diff --git a/spec/features/projects/fork_spec.rb b/spec/features/projects/fork_spec.rb index cd5fef8238e..7c71b4c52e0 100644 --- a/spec/features/projects/fork_spec.rb +++ b/spec/features/projects/fork_spec.rb @@ -53,6 +53,18 @@ describe 'Project fork' do expect(current_path).to have_content(/#{user.namespace.name}/i) end + it 'shows avatars when Gravatar is disabled' do + stub_application_setting(gravatar_enabled: false) + + visit project_path(project) + + click_link 'Fork' + + page.within('.fork-thumbnail-container') do + expect(page).to have_css('div.identicon') + end + end + it 'shows the forked project on the list' do visit project_path(project) diff --git a/spec/helpers/avatars_helper_spec.rb b/spec/helpers/avatars_helper_spec.rb index 55ee87163f9..aa0442ab847 100644 --- a/spec/helpers/avatars_helper_spec.rb +++ b/spec/helpers/avatars_helper_spec.rb @@ -32,18 +32,6 @@ describe AvatarsHelper do end end - context 'when providing a project path' do - it_behaves_like 'resource with a default avatar', 'project' do - let(:resource) { create(:project, name: 'foo') } - let(:helper_args) { [resource.full_path] } - end - - it_behaves_like 'resource with a custom avatar', 'project' do - let(:resource) { create(:project, :public, avatar: File.open(uploaded_image_temp_path)) } - let(:helper_args) { [resource.full_path] } - end - end - context 'when providing a group' do it_behaves_like 'resource with a default avatar', 'group' do let(:resource) { create(:group, name: 'foo') } @@ -55,18 +43,6 @@ describe AvatarsHelper do let(:helper_args) { [resource] } end end - - context 'when providing a group path' do - it_behaves_like 'resource with a default avatar', 'group' do - let(:resource) { create(:group, name: 'foo') } - let(:helper_args) { [resource.full_path] } - end - - it_behaves_like 'resource with a custom avatar', 'group' do - let(:resource) { create(:group, avatar: File.open(uploaded_image_temp_path)) } - let(:helper_args) { [resource.full_path] } - end - end end describe '#avatar_icon_for' do |