FIX: Do not allow_any on fonts site_settings (#30780)

Both heading_font and body_font should not allow
additional user-defined values, these are lists with
predefined choices. The UI already prevents this
because the font selector dropdown is unique, but
we want to make sure the setting definition reflects
this too.
This commit is contained in:
Martin Brennan
2025-01-15 14:13:34 +10:00
committed by GitHub
parent 5bc522e836
commit 125e686bf2
2 changed files with 7 additions and 1 deletions

View File

@@ -414,6 +414,7 @@ basic:
type: list type: list
list_type: font list_type: font
area: "fonts" area: "fonts"
allow_any: false
heading_font: heading_font:
default: "arial" default: "arial"
choices: "BaseFontSetting.values" choices: "BaseFontSetting.values"
@@ -421,6 +422,7 @@ basic:
type: list type: list
list_type: font list_type: font
area: "fonts" area: "fonts"
allow_any: false
enable_sitemap: enable_sitemap:
default: true default: true
sitemap_page_size: sitemap_page_size:

View File

@@ -269,7 +269,11 @@ class SiteSettings::TypeSupervisor
if type == self.class.types[:list] || type == self.class.types[:string] if type == self.class.types[:list] || type == self.class.types[:string]
if @allow_any.key?(name) && !@allow_any[name] if @allow_any.key?(name) && !@allow_any[name]
split = val.to_s.split("|") split = val.to_s.split("|")
diff = (split - @choices[name]) resolved_choices = @choices[name]
if resolved_choices.first.is_a?(Hash)
resolved_choices = resolved_choices.map { |c| c[:value] }
end
diff = (split - resolved_choices)
if diff.length > 0 if diff.length > 0
raise Discourse::InvalidParameters.new( raise Discourse::InvalidParameters.new(
I18n.t( I18n.t(