FIX: Use CDN urls for theme settings of type upload (#12773)

FIX: Use CDN urls for theme settings of type upload (#12773)

diff --git a/app/models/theme.rb b/app/models/theme.rb
index c396c83..1ac7d34 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -128,7 +128,7 @@ class Theme < ActiveRecord::Base
     SvgSprite.expire_cache
   end
 
-  BASE_COMPILER_VERSION = 49
+  BASE_COMPILER_VERSION = 50
   def self.compiler_version
     get_set_cache "compiler_version" do
       dependencies = [
diff --git a/lib/theme_settings_manager.rb b/lib/theme_settings_manager.rb
index 968f6e9..7ebbcc2 100644
--- a/lib/theme_settings_manager.rb
+++ b/lib/theme_settings_manager.rb
@@ -173,5 +173,10 @@ class ThemeSettingsManager
   end
 
   class Upload < self
+    def value
+      val = super
+      Discourse.store.cdn_url(val)
+    end
+
   end
 end
diff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rb
index d9b5df2..d4e9767 100644
--- a/spec/models/theme_spec.rb
+++ b/spec/models/theme_spec.rb
@@ -531,6 +531,24 @@ HTML
     expect(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' do
     Theme.destroy_all
 

GitHub sha: c47e6a20

This commit appears in #12773 which was approved by davidtaylorhq. It was merged by pmusaraj.