discourse/app/services/site_setting/policy/values_are_valid.rb
Ted Johansson b40cbfcb76
DEV: Move backfill into SiteSetting::Update service (#32037)
Some site settings support backfilling if the user specified it. This works fine for singular site settings sent to the SiteSettingsController#update endpoint, but with bulk save we need to support this for a list of settings as well.

This change alters the params format for SiteSetting::Update.

It also moves the backfill logic into the service.
2025-03-28 12:01:56 +08:00

26 lines
616 B
Ruby
Vendored

# frozen_string_literal: true
class SiteSetting::Policy::ValuesAreValid < Service::PolicyBase
delegate :options, :params, to: :context
def call
@setting_errors = params.settings.filter_map(&method(:validate_setting))
@setting_errors.empty?
end
def reason
@setting_errors.join(", ")
end
private
def validate_setting(setting)
setting_type = SiteSetting.type_supervisor.get_type(setting.name)
begin
SiteSetting.type_supervisor.validate_value(setting.name, setting_type, setting.value)
nil
rescue Discourse::InvalidParameters => e
e.message
end
end
end