0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/config/initializers/015-track-upcoming-change-toggle.rb
David Battersby 1b33298435
DEV: remove and replace Uncategorized (#41169)
Removes the Uncategorized category concept to reduce product complexity.

We are using an Upcoming Change to safely manage this migration and
removal. Part of that process is storing a snapshot of settings prior to
toggling the change (either manually or via promotion) so we can easily
opt out later without causing disruption.

When enabled we hide the following site settings from the admin screen,
all of which will be removed when the change reaches the `permanent`
status:

- allow_uncategorized_topics
- suppress_uncategorized_badge
- uncategorized_category_id

Internal ref: /t/183820
2026-07-07 09:15:55 +04:00

39 lines
1.9 KiB
Ruby
Vendored

# frozen_string_literal: true
Rails.application.config.after_initialize { UpcomingChanges.clear_caches! }
#
# Similar to 014-track-setting-changes.rb, we can react to upcoming changes
# being enabled/or disabled here for more complicated scenarios, where
# we are not just changing UI or behaviour when the state of the underlying
# setting is changed.
#
# We need to do this separately from 014-track-setting-changes.rb because
# we don't actually change the underlying setting value in the database
# when an upcoming change is automatically promoted. See UpcomingChanges::NotifyPromotions
# for further context.
#
# We do also send these events when admins manually opt-in or opt-out of an upcoming change
# via the UI and the UpcomingChanges::Toggle service.
DiscourseEvent.on(:upcoming_change_enabled) do |setting_name|
# Respond to event here, e.g. if setting_name == :enable_form_templates do X.
if setting_name == :simple_email_subject
SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: true })
elsif setting_name == :enable_horizon_high_context_topic_cards
Themes::Action::HorizonHighContextTopicCardsToggled.call(enabled: true)
elsif setting_name == :remove_and_replace_uncategorized
SiteSetting::Action::RemoveAndReplaceUncategorizedToggled.call(enabled: true)
end
end
DiscourseEvent.on(:upcoming_change_disabled) do |setting_name|
# Respond to event here, e.g. if setting_name == :enable_form_templates do X.
if setting_name == :simple_email_subject
SiteSetting::Action::SimpleEmailSubjectToggled.call(params: { setting_enabled: false })
elsif setting_name == :enable_horizon_high_context_topic_cards
Themes::Action::HorizonHighContextTopicCardsToggled.call(enabled: false)
elsif setting_name == :remove_and_replace_uncategorized
SiteSetting::Action::RemoveAndReplaceUncategorizedToggled.call(enabled: false)
end
end