0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/lib/theme_settings_manager/objects.rb
Gabriel Grubba e52b385ae1
FIX: type: objects uploads should be stored as IDs (#40178)
Inside `type objects` we accepted upload URLs and converted them into
IDs, but we did not update the original object to have an ID.

Only on consuming should we turn the ID into a URL.

For normal front-end consumers, object upload fields should still be
URLs. Backend consumers should expect upload IDs.

<img width="2295" height="1263" alt="Screenshot 2026-05-20 at 12 19 23"
src="https://github.com/user-attachments/assets/20d411c4-1570-45fc-96c8-02f2b1b3639d"
/>
2026-05-21 13:45:27 -03:00

49 lines
1.2 KiB
Ruby
Vendored

# frozen_string_literal: true
class ThemeSettingsManager::Objects < ThemeSettingsManager
def self.extract_value_from_row(row)
row.json_value
end
def default
hydrate_uploads(@default.map(&:deep_stringify_keys))
end
def value
has_record? ? hydrate_uploads(db_record.json_value) : default
end
def value=(objects)
objects = JSON.parse(objects) if objects.is_a?(::String)
ensure_is_valid_value!(objects)
objects = SchemaSettingsObjectValidator.normalize_uploads(schema:, 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 hydrate_uploads(objects)
SchemaSettingsObjectValidator.hydrate_uploads(schema:, objects:, cdn: true)
end
def categories(guardian)
category_ids = Set.new
value.each do |theme_setting_object|
category_ids.merge(
SchemaSettingsObjectValidator.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