FIX: Use the default value correctly for theme settings of type uploads (#20541)

When a theme setting of type `upload` has a default upload, it should return the URL of the specified default upload until a custom upload is used for the setting. However, currently this isn't the case and we get null instead of the default upload URL.

The reason for this is because the `super` method of `#value` already returns the default upload URL (if there's one), so we can't pass that to `cdn_url` which expects an upload ID:

c961dcc757/lib/theme_settings_manager.rb (L212)

This commit fixes the bug by skipping the call to `cdn_url` when we fallback to the default upload for the setting value.
This commit is contained in:
Osama Sayegh 2023-03-06 11:41:47 +03:00 committed by GitHub
parent c961dcc757
commit 3f908c047d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 7 deletions

View File

@ -184,7 +184,7 @@ class ThemeSettingsManager
class Upload < self
def value
cdn_url(super)
has_record? ? cdn_url(db_record.value) : default
end
def default

View File

@ -71,7 +71,7 @@ enum_setting_03:
upload_setting:
type: upload
default: ""
default: "default-upload"
invalid_json_schema_setting:
default: ""

View File

@ -161,12 +161,30 @@ RSpec.describe ThemeSettingsManager do
).to be_truthy
end
it "returns the CDN URL" do
upload_setting = find_by_name(:upload_setting)
upload_setting.value = upload.url
theme.reload
describe "#value" do
context "when it's changed to a custom upload" do
it "returns CDN URL" do
upload_setting = find_by_name(:upload_setting)
upload_setting.value = upload.url
theme.reload
expect(upload_setting.value).to eq(Discourse.store.cdn_url(upload.url))
expect(upload_setting.value).to eq(Discourse.store.cdn_url(upload.url))
end
end
context "when there's a default upload" do
it "returns CDN URL" do
theme.set_field(
target: :common,
name: "default-upload",
type: :theme_upload_var,
upload_id: upload.id,
)
theme.save!
upload_setting = find_by_name(:upload_setting)
expect(upload_setting.value).to eq(Discourse.store.cdn_url(upload.url))
end
end
end
end
end