mirror of
https://github.com/discourse/discourse.git
synced 2025-06-08 00:27:32 +08:00
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:
@ -184,7 +184,7 @@ class ThemeSettingsManager
|
|||||||
|
|
||||||
class Upload < self
|
class Upload < self
|
||||||
def value
|
def value
|
||||||
cdn_url(super)
|
has_record? ? cdn_url(db_record.value) : default
|
||||||
end
|
end
|
||||||
|
|
||||||
def default
|
def default
|
||||||
|
@ -71,7 +71,7 @@ enum_setting_03:
|
|||||||
|
|
||||||
upload_setting:
|
upload_setting:
|
||||||
type: upload
|
type: upload
|
||||||
default: ""
|
default: "default-upload"
|
||||||
|
|
||||||
invalid_json_schema_setting:
|
invalid_json_schema_setting:
|
||||||
default: ""
|
default: ""
|
||||||
|
@ -161,7 +161,9 @@ RSpec.describe ThemeSettingsManager do
|
|||||||
).to be_truthy
|
).to be_truthy
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the CDN URL" do
|
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 = find_by_name(:upload_setting)
|
||||||
upload_setting.value = upload.url
|
upload_setting.value = upload.url
|
||||||
theme.reload
|
theme.reload
|
||||||
@ -169,4 +171,20 @@ RSpec.describe ThemeSettingsManager do
|
|||||||
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
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user