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

24 lines
604 B
Ruby

# frozen_string_literal: true
class SiteSetting::Policy::SettingsAreVisible < Service::PolicyBase
delegate :options, :params, to: :context
def call
@hidden_settings = params.settings.map(&:name).select(&method(:validate_setting))
@hidden_settings.empty?
end
def reason
I18n.t(
"errors.site_settings.site_settings_are_hidden",
setting_names: @hidden_settings.join(", "),
)
end
private
def validate_setting(setting_name)
return false if options.allow_changing_hidden.include?(setting_name)
SiteSetting.hidden_settings.include?(setting_name)
end
end