Commit 0a74ee3f authored by Gabriel Mazetto's avatar Gabriel Mazetto

Patch Project, Group and User to display correct avatar from Primary node

parent c07b2c04
...@@ -8,11 +8,7 @@ module GroupsHelper ...@@ -8,11 +8,7 @@ module GroupsHelper
group = Group.find_by(path: group) group = Group.find_by(path: group)
end end
if group && group.avatar.present? group.try(:avatar_url) || image_path('no_group_avatar.png')
group.avatar.url
else
image_path('no_group_avatar.png')
end
end end
def group_title(group, name = nil, url = nil) def group_title(group, name = nil, url = nil)
......
# Group EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be included in the `Group` model
module EE module EE
# Group EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be included in the `Group` model
module Group module Group
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
prepend GeoFeatures
state_machine :ldap_sync_status, namespace: :ldap_sync, initial: :ready do state_machine :ldap_sync_status, namespace: :ldap_sync, initial: :ready do
state :ready state :ready
state :started state :started
...@@ -55,5 +57,15 @@ module EE ...@@ -55,5 +57,15 @@ module EE
fail_ldap_sync fail_ldap_sync
update_column(:ldap_sync_error, ::Gitlab::UrlSanitizer.sanitize(error_message)) update_column(:ldap_sync_error, ::Gitlab::UrlSanitizer.sanitize(error_message))
end end
module GeoFeatures
def avatar_url(size = nil)
if self[:avatar].present? && ::Gitlab::Geo.secondary?
File.join(::Gitlab::Geo.primary_node.url, avatar.url)
else
super
end
end
end
end end
end end
module EE
# Project EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be **prepended** in the `Project` model
module Project
# Display correct avatar in a secondary Geo node
def avatar_url
if self[:avatar].present? && ::Gitlab::Geo.secondary?
File.join(::Gitlab::Geo.primary_node.url, avatar.url)
else
super
end
end
end
end
module EE
# User EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be **prepended** in the `User` model
module User
def avatar_url(size = nil, scale = 2)
if self[:avatar].present? && ::Gitlab::Geo.secondary?
File.join(::Gitlab::Geo.primary_node.url, avatar.url)
else
super
end
end
end
end
...@@ -15,6 +15,7 @@ class Project < ActiveRecord::Base ...@@ -15,6 +15,7 @@ class Project < ActiveRecord::Base
include Elastic::ProjectsSearch include Elastic::ProjectsSearch
include ProjectFeaturesCompatibility include ProjectFeaturesCompatibility
include SelectForProjectAuthorization include SelectForProjectAuthorization
prepend EE::Project
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
......
...@@ -9,6 +9,7 @@ class User < ActiveRecord::Base ...@@ -9,6 +9,7 @@ class User < ActiveRecord::Base
include Sortable include Sortable
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
prepend EE::User
DEFAULT_NOTIFICATION_LEVEL = :participating DEFAULT_NOTIFICATION_LEVEL = :participating
......
---
title: Geo: Display Custom Avatars in secondary nodes
merge_request: 904
author:
...@@ -18,7 +18,7 @@ module EE ...@@ -18,7 +18,7 @@ module EE
# Geo should only update Redis based cache, as data store in the database # Geo should only update Redis based cache, as data store in the database
# will be updated on primary and replicated to the secondaries. # will be updated on primary and replicated to the secondaries.
def perform_geo_secondary(project_id, refresh = []) def perform_geo_secondary(project_id, refresh = [])
project = Project.find_by(id: project_id) project = ::Project.find_by(id: project_id)
return unless project && project.repository.exists? return unless project && project.repository.exists?
......
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