FEATURE: Introduce site settings which require confirmation (#27315)

Many site settings can be distructive or have huge side-effects
for a site that the admin may not be aware of when changing it.

This commit introduces a `requires_confirmation` attribute that
can be added to any site setting. When it is true, a confirmation
dialog will open if that setting is changed in the admin UI,
optionally with a custom message that is defined in client.en.yml.

If the admin does not confirm, we reset the setting to its previous
clean value and do not save the new value.
This commit is contained in:
Martin Brennan
2024-06-19 16:01:24 +10:00
committed by GitHub
parent 3ff7ce78e7
commit 83361b2fc5
12 changed files with 187 additions and 10 deletions

View File

@@ -95,6 +95,10 @@ module SiteSettingExtension
@shadowed_settings ||= []
end
def requires_confirmation_settings
@requires_confirmation_settings ||= {}
end
def hidden_settings_provider
@hidden_settings_provider ||= SiteSettings::HiddenProvider.new
end
@@ -244,6 +248,7 @@ module SiteSettingExtension
secret: secret_settings.include?(s),
placeholder: placeholder(s),
mandatory_values: mandatory_values[s],
requires_confirmation: requires_confirmation_settings[s],
}.merge!(type_hash)
opts[:plugin] = plugins[s] if plugins[s]
@@ -654,6 +659,14 @@ module SiteSettingExtension
mandatory_values[name] = opts[:mandatory_values] if opts[:mandatory_values]
requires_confirmation_settings[name] = (
if SiteSettings::TypeSupervisor::REQUIRES_CONFIRMATION_TYPES.values.include?(
opts[:requires_confirmation],
)
opts[:requires_confirmation]
end
)
categories[name] = opts[:category] || :uncategorized
hidden_settings_provider.add_hidden(name) if opts[:hidden]