Commit c90803d9 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'da-geo-fix-user-avatar-being-user-from-primary-node' into 'master'

Remove EE::GeoAwareAvatar

Closes #4143

See merge request gitlab-org/gitlab-ee!3857
parents 41313ee9 14ad50e8
......@@ -12,7 +12,6 @@ class Group < Namespace
include SelectForProjectAuthorization
include LoadedInGroupList
include GroupDescendant
prepend EE::GeoAwareAvatar
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source # rubocop:disable Cop/ActiveRecordDependent
alias_method :members, :group_members
......
......@@ -20,7 +20,6 @@ class User < ActiveRecord::Base
include BulkMemberAccessLoad
include BlocksJsonSerialization
prepend EE::GeoAwareAvatar
prepend EE::User
DEFAULT_NOTIFICATION_LEVEL = :participating
......
---
title: Geo - Use relative path for avatar images on a secondary node
merge_request: 3857
author:
type: fixed
module EE
# Avatars in Geo mixin
#
# This module is intended to encapsulate Geo-specific logic
# and be **prepended** in the `Group`, `User`, `Project` models
module GeoAwareAvatar
def avatar_url(**args)
if ::Gitlab::Geo.secondary? && self[:avatar].present?
File.join(::Gitlab::Geo.primary_node.url, avatar.url)
else
super
end
end
end
end
......@@ -9,7 +9,6 @@ module EE
prepended do
include Elastic::ProjectsSearch
prepend GeoAwareAvatar
prepend ImportStatusStateMachine
before_validation :mark_remote_mirrors_for_removal
......
......@@ -32,27 +32,6 @@ describe GroupsHelper do
group.save!
expect(group_icon_url(group.path)).to match_asset_path('group_avatar.png')
end
context 'in a geo secondary node' do
let(:group) { create(:group) }
let(:geo_url) { 'http://geo.example.com' }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it 'returns an url for the avatar pointing to the primary node base url' do
group.avatar = fixture_file_upload(avatar_file_path)
group.save!
expect(group_icon_url(group.path)).to match("#{geo_url}/uploads/-/system/group/avatar/#{group.id}/banana_sample.gif")
end
it 'gives default avatar_icon when no avatar is present' do
group.save!
expect(group_icon_url(group.path)).to match_asset_path('no_group_avatar.png')
end
end
end
describe 'group_lfs_status' do
......
......@@ -258,26 +258,6 @@ describe Group do
expect(group.avatar_url).to eq(group.avatar.url)
expect(group.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, group.avatar.url].join)
end
context 'when in a geo secondary node' do
let(:avatar_path) { group.avatar_path(only_path: true) }
let(:geo_host) { 'http://geo.example.com' }
let(:geo_avatar_url) { [geo_host, avatar_path].join }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_host }
end
it 'shows correct avatar url' do
expect(group.avatar_url).to eq(geo_avatar_url)
expect(group.avatar_url(only_path: false)).to eq(geo_avatar_url)
allow(ActionController::Base).to receive(:asset_host).and_return(geo_host)
expect(group.avatar_url).to eq(geo_avatar_url)
end
end
end
end
......
......@@ -1047,18 +1047,6 @@ describe Project do
expect(project.avatar_url).to eq(project.avatar.url)
expect(project.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, project.avatar.url].join)
end
context 'When in a geo secondary node' do
let(:geo_url) { 'http://geo.example.com' }
let(:avatar_path) { project.avatar_path(only_path: true) }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_url }
end
it { is_expected.to eq "#{geo_url}#{avatar_path}" }
end
end
context 'when avatar file in git' do
......
......@@ -1191,26 +1191,6 @@ describe User do
expect(user.avatar_url).to eq(user.avatar.url)
expect(user.avatar_url(only_path: false)).to eq([Gitlab.config.gitlab.url, user.avatar.url].join)
end
context 'when in a geo secondary node' do
let(:avatar_path) { user.avatar_path(only_path: true) }
let(:geo_host) { 'http://geo.example.com' }
let(:geo_avatar_url) { [geo_host, avatar_path].join }
before do
allow(Gitlab::Geo).to receive(:secondary?) { true }
allow(Gitlab::Geo).to receive_message_chain(:primary_node, :url) { geo_host }
end
it 'shows correct avatar url' do
expect(user.avatar_url).to eq(geo_avatar_url)
expect(user.avatar_url(only_path: false)).to eq(geo_avatar_url)
allow(ActionController::Base).to receive(:asset_host).and_return(geo_host)
expect(user.avatar_url).to eq(geo_avatar_url)
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