summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-11-09 15:40:41 +0000
committerWinnie Hellmann <winnie@gitlab.com>2017-11-17 11:55:21 +0000
commitabb6de2245d2aba9e0242ca3709a04f648a099e8 (patch)
tree671651a550391842ecfa9215d16b5e4319a62eab /app
parent24290d5da5c4a7abb8d7130266e594566f7c0654 (diff)
downloadgitlab-ce-abb6de2245d2aba9e0242ca3709a04f648a099e8.tar.gz
Merge branch 'dm-avatarable-with-asset-host' into 'master'
Always return full avatar URL for private/internal groups/projects when asset host is set See merge request gitlab-org/gitlab-ce!15288 (cherry picked from commit f24a78f2801608be7c3b9d3a0dad90656880f097) 0cf25867 Always return full avatar URL for private/internal groups/projects when asset host is set d4babd26 Remove specs that are testing behavior already tested in Avatarable unit tests
Diffstat (limited to 'app')
-rw-r--r--app/models/concerns/avatarable.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb
index 2ec70203710..10659030910 100644
--- a/app/models/concerns/avatarable.rb
+++ b/app/models/concerns/avatarable.rb
@@ -4,15 +4,26 @@ module Avatarable
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
+ use_asset_host = asset_host.present?
- # 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? && (!respond_to?(:public?) || public?)) ? asset_host : gitlab_host
+ # 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
- [host, avatar.url].join
+ 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
end
end