summaryrefslogtreecommitdiff
path: root/app/models/appearance.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-12-25 00:24:00 -0800
committerStan Hu <stanhu@gmail.com>2018-12-25 08:22:34 -0800
commit7036f75f6710d5b2cb188864c3c75e06721a755f (patch)
tree75d10c9f6ed4e332a3dec12ebb63e04b1f4a60b2 /app/models/appearance.rb
parent5dc656fc1f053d397ad1e6c1d85a815f03a5d634 (diff)
downloadgitlab-ce-7036f75f6710d5b2cb188864c3c75e06721a755f.tar.gz
Use system paths for appearance logos
When object storage is enabled, the logos used to customize a GitLab appearance causes the time-limited URLs to be used. We fix this by forcing all of these URLs to use the /uploads/-/system prefix so that they will always be proxied through GitLab. Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/6778
Diffstat (limited to 'app/models/appearance.rb')
-rw-r--r--app/models/appearance.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/models/appearance.rb b/app/models/appearance.rb
index bffba3e13fa..e114c435b67 100644
--- a/app/models/appearance.rb
+++ b/app/models/appearance.rb
@@ -28,4 +28,32 @@ class Appearance < ActiveRecord::Base
errors.add(:single_appearance_row, 'Only 1 appearances row can exist')
end
end
+
+ def logo_path
+ logo_system_path(logo, 'logo')
+ end
+
+ def header_logo_path
+ logo_system_path(header_logo, 'header_logo')
+ end
+
+ def favicon_path
+ logo_system_path(favicon, 'favicon')
+ end
+
+ private
+
+ def logo_system_path(logo, mount_type)
+ return unless logo&.upload
+
+ # If we're using a CDN, we need to use the full URL
+ asset_host = ActionController::Base.asset_host
+ local_path = Gitlab::Routing.url_helpers.appearance_upload_path(
+ filename: logo.filename,
+ id: logo.upload.model_id,
+ model: 'appearance',
+ mounted_as: mount_type)
+
+ Gitlab::Utils.append_path(asset_host, local_path)
+ end
end