discourse/lib/theme_settings_manager/objects.rb
Osama Sayegh 2215fa0c8e
FIX: Pass values of objects typed settings to theme migrations (#26751)
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.
2024-04-25 16:39:22 +03:00

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