discourse/app/services/site_setting/policy/settings_are_not_deprecated.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

33 lines
869 B
Ruby
Vendored

# frozen_string_literal: true
class SiteSetting::Policy::SettingsAreNotDeprecated < Service::PolicyBase
delegate :options, :params, to: :context
def call
@hard_deprecations =
params.settings.filter_map do |setting|
SiteSettings::DeprecatedSettings::SETTINGS.find do |old_name, new_name, override, _|
if old_name.to_sym == setting.name
if override
options.overridden_setting_names[old_name.to_sym] = new_name
break
else
break old_name, new_name
end
end
end
end
@hard_deprecations.empty?
end
def reason
old_names, new_names = @hard_deprecations.transpose
I18n.t(
"errors.site_settings.site_settings_are_deprecated",
old_names: old_names.join(", "),
new_names: new_names.join(", "),
)
end
end