diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2017-05-10 07:26:17 +0300 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2017-05-10 07:26:17 +0300 |
commit | 29a3203b3fe08649b80def65b7750a866454d3d6 (patch) | |
tree | d4e644c142b1ecc6dd869c636ad5657c546d901b /app/models/concerns/avatarable.rb | |
parent | ecc6cc8be75b5c66fdf7f5595b71aabf9366a5e1 (diff) |
Use relative paths for group/project/user avatars
Diffstat (limited to 'app/models/concerns/avatarable.rb')
-rw-r--r-- | app/models/concerns/avatarable.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb new file mode 100644 index 00000000000..8fbfed11bdf --- /dev/null +++ b/app/models/concerns/avatarable.rb @@ -0,0 +1,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 |