summaryrefslogtreecommitdiff
path: root/app/models/concerns/avatarable.rb
blob: 8fbfed11bdf50c0dd7c180d851148b6f77dfcd98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
module Avatarable
  extend ActiveSupport::Concern

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

    # If only_path is true then use the relative path of avatar.
    # Otherwise use full path (including host).
    asset_host = ActionController::Base.asset_host
    gitlab_host = only_path ? gitlab_config.relative_url_root : gitlab_config.url

    # If asset_host is set then it is expected that assets are handled by a standalone host.
    # That means we do not want to get GitLab's relative_url_root option anymore.
    host = asset_host.present? ? asset_host : gitlab_host

    [host, avatar.url].join
  end
end