BigW Consortium Gitlab

avatarable.rb 938 Bytes
Newer Older
1 2 3
module Avatarable
  extend ActiveSupport::Concern

4
  def avatar_path(only_path: true)
5 6 7
    return unless self[:avatar].present?

    asset_host = ActionController::Base.asset_host
8
    use_asset_host = asset_host.present?
9

10 11 12 13 14 15 16 17
    # Avatars for private and internal groups and projects require authentication to be viewed,
    # which means they can only be served by Rails, on the regular GitLab host.
    # If an asset host is configured, we need to return the fully qualified URL
    # instead of only the avatar path, so that Rails doesn't prefix it with the asset host.
    if use_asset_host && respond_to?(:public?) && !public?
      use_asset_host = false
      only_path = false
    end
18

19 20 21 22 23 24 25 26 27
    url_base = ""
    if use_asset_host
      url_base << asset_host unless only_path
    else
      url_base << gitlab_config.base_url unless only_path
      url_base << gitlab_config.relative_url_root
    end

    url_base + avatar.url
28 29
  end
end