gitlab-org--gitlab-foss/app/models/concerns/avatarable.rb

19 lines
688 B
Ruby
Raw Normal View History

module Avatarable
extend ActiveSupport::Concern
2017-10-09 04:45:23 -04:00
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
2017-10-05 10:29:45 -04:00
# 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.
2017-10-09 04:45:23 -04:00
host = (asset_host.present? && (!respond_to?(:public?) || public?)) ? asset_host : gitlab_host
2017-10-02 09:44:58 -04:00
[host, avatar.url].join
end
end