mirror of
https://github.com/discourse/discourse.git
synced 2024-12-30 08:43:53 +08:00
2215fa0c8e
This commit fixes a bug in theme settings migrations where values of `objects` typed theme settings aren't passed to migrations even when there are overriding values for those settings. What causes this bug is that, when creating the hash that contains all the overridden settings and will be passed to migrations, the values of `objects` typed settings are incorrectly retrieved from the `value` column (which is always nil for `objects` type) instead of `json_value`. `objects` settings are different from all other types in that they store their values in the `json_value` column and they need to be special-cased when retrieving their values.
41 lines
948 B
Ruby
41 lines
948 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsManager::Objects < ThemeSettingsManager
|
|
def self.extract_value_from_row(row)
|
|
row.json_value
|
|
end
|
|
|
|
def value
|
|
has_record? ? db_record.json_value : default.map!(&:deep_stringify_keys)
|
|
end
|
|
|
|
def value=(objects)
|
|
objects = JSON.parse(objects) if objects.is_a?(::String)
|
|
ensure_is_valid_value!(objects)
|
|
record = has_record? ? update_record!(json_value: objects) : create_record!(json_value: objects)
|
|
theme.reload
|
|
record.json_value
|
|
end
|
|
|
|
def schema
|
|
@opts[:schema]
|
|
end
|
|
|
|
def categories(guardian)
|
|
category_ids = Set.new
|
|
|
|
value.each do |theme_setting_object|
|
|
category_ids.merge(
|
|
ThemeSettingsObjectValidator.new(
|
|
schema:,
|
|
object: theme_setting_object,
|
|
).property_values_of_type("categories"),
|
|
)
|
|
end
|
|
|
|
return [] if category_ids.empty?
|
|
|
|
Category.secured(guardian).where(id: category_ids)
|
|
end
|
|
end
|