mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 22:05:48 +08:00
476d91d233
Why this change?
This is a follow-up to 86b2e3aa3e
.
Basically, we want to allow people to select more than 1 category as well.
What does this change do?
1. Change `type: category` to `type: categories` and support `min` and `max`
validations for `type: categories`.
2. Fix the `<SchemaThemeSetting::Types::Categories>` component to support the
`min` and `max` validations and switch it to use the `<CategorySelector>` component
instead of the `<CategoryChooser>` component which only supports selecting one category.
37 lines
883 B
Ruby
37 lines
883 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsManager::Objects < ThemeSettingsManager
|
|
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
|