mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 08:11:11 +08:00
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.
26 lines
616 B
Ruby
Vendored
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
|