Commit 259c23dd authored by Gabriel Mazetto's avatar Gabriel Mazetto

Refactor to remove duplicated code in Geo aware avatars

parent b31462ae
module EE module EE
# User EE mixin # Avatars in Geo mixin
# #
# This module is intended to encapsulate EE-specific model logic # This module is intended to encapsulate Geo-specific logic
# and be **prepended** in the `User` model # and be **prepended** in the `Group`, `User`, `Project` models
module User module GeoAwareAvatar
def avatar_url(size = nil, scale = 2) def avatar_url(size = nil)
if self[:avatar].present? && ::Gitlab::Geo.secondary? if self[:avatar].present? && ::Gitlab::Geo.secondary?
File.join(::Gitlab::Geo.primary_node.url, avatar.url) File.join(::Gitlab::Geo.primary_node.url, avatar.url)
else else
super super()
end end
end end
end end
......
...@@ -7,8 +7,6 @@ module EE ...@@ -7,8 +7,6 @@ module EE
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
...@@ -57,15 +55,5 @@ module EE ...@@ -57,15 +55,5 @@ 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
...@@ -9,6 +9,7 @@ class Group < Namespace ...@@ -9,6 +9,7 @@ class Group < Namespace
include AccessRequestable include AccessRequestable
include Referable include Referable
include SelectForProjectAuthorization include SelectForProjectAuthorization
prepend EE::GeoAwareAvatar
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source
alias_method :members, :group_members alias_method :members, :group_members
......
...@@ -15,7 +15,7 @@ class Project < ActiveRecord::Base ...@@ -15,7 +15,7 @@ class Project < ActiveRecord::Base
include Elastic::ProjectsSearch include Elastic::ProjectsSearch
include ProjectFeaturesCompatibility include ProjectFeaturesCompatibility
include SelectForProjectAuthorization include SelectForProjectAuthorization
prepend EE::Project prepend EE::GeoAwareAvatar
extend Gitlab::ConfigHelper extend Gitlab::ConfigHelper
......
...@@ -9,7 +9,7 @@ class User < ActiveRecord::Base ...@@ -9,7 +9,7 @@ class User < ActiveRecord::Base
include Sortable include Sortable
include CaseSensitivity include CaseSensitivity
include TokenAuthenticatable include TokenAuthenticatable
prepend EE::User prepend EE::GeoAwareAvatar
DEFAULT_NOTIFICATION_LEVEL = :participating DEFAULT_NOTIFICATION_LEVEL = :participating
......
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