0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/lib/site_settings/hidden_provider.rb
David Battersby 23691594c0
DEV: Add hide_settings metadata to upcoming changes framework (#40990)
Adds an optional `hide_settings:` key to `upcoming_change` metadata in
`site_settings.yml`. It declares other site settings that should be
hidden from admins while the change is enabled (manual opt-in or
auto-promotion) — useful for legacy settings that stop making sense once
the change replaces them.

The hidden set is computed live by
`UpcomingChanges.settings_hidden_while_enabled` and consulted by
`SiteSettings::HiddenProvider#all`, rather than toggled imperatively at
opt-in time.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 10:25:39 +04:00

32 lines
958 B
Ruby
Vendored

# frozen_string_literal: true
module SiteSettings
end
# A class to store and modify hidden site settings
class SiteSettings::HiddenProvider
def initialize
@hidden_settings = Set.new
end
def add_hidden(site_setting_name)
@hidden_settings << site_setting_name
end
def remove_hidden(site_setting_name)
@hidden_settings.delete(site_setting_name)
end
def all
hidden = @hidden_settings
# Settings hidden because an upcoming change that replaces them is enabled.
# Unioned before the modifier so plugins can still explicitly un-hide a
# setting via the :hidden_site_settings modifier. Skipped entirely when no
# change opts in, to avoid allocating a new Set on every read.
upcoming_change_hidden = UpcomingChanges.settings_hidden_while_enabled
hidden = hidden | upcoming_change_hidden if upcoming_change_hidden.present?
DiscoursePluginRegistry.apply_modifier(:hidden_site_settings, hidden)
end
end