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

This commit is contained in:
Penar Musaraj 2021-04-20 18:42:02 -04:00 committed by GitHub
parent d51a226da4
commit c47e6a2004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -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 = [

View File

@ -173,5 +173,10 @@ class ThemeSettingsManager
end
class Upload < self
def value
val = super
Discourse.store.cdn_url(val)
end
end
end

View File

@ -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