A platform for community discussion. Free, open, simple.
FIX: Use CDN urls for theme settings of type upload (#12773)
Penar Musarajc47e6a200435
diff --git a/app/models/theme.rb b/app/models/theme.rbindex c396c831f89..1ac7d34489c 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -128,7 +128,7 @@ class Theme < ActiveRecord::BaseSvgSprite.expire_cacheend- BASE_COMPILER_VERSION = 49+ BASE_COMPILER_VERSION = 50def self.compiler_versionget_set_cache "compiler_version" dodependencies = [diff --git a/lib/theme_settings_manager.rb b/lib/theme_settings_manager.rbindex 968f6e9e23a..7ebbcc21418 100644--- a/lib/theme_settings_manager.rb+++ b/lib/theme_settings_manager.rb@@ -173,5 +173,10 @@ class ThemeSettingsManagerendclass Upload < self+ def value+ val = super+ Discourse.store.cdn_url(val)+ end+endenddiff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rbindex d9b5df23e26..d4e97677f87 100644--- a/spec/models/theme_spec.rb+++ b/spec/models/theme_spec.rb@@ -531,6 +531,24 @@ HTMLexpect(json["theme_uploads"]["bob"]).to eq("http://cdn.localhost#{upload.url}")end+ it 'uses CDN url for settings of type upload' do+ set_cdn_url("http://cdn.localhost")+ Theme.destroy_all++ upload = UploadCreator.new(file_from_fixtures("logo.png"), "logo.png").create_for(-1)+ theme.set_field(target: :settings, name: "yaml", value: <<~YAML)+ my_upload:+ type: upload+ default: ""+ YAML++ ThemeSetting.create!(theme: theme, data_type: ThemeSetting.types[:upload], value: upload.url, name: "my_upload")+ theme.save!++ json = JSON.parse(cached_settings(theme.id))+ expect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")+ end+it 'handles settings cache correctly' doTheme.destroy_all