A platform for community discussion. Free, open, simple.
DEV: hide and disable upcoming changes for disabled plugins (#41657)
David Battersbya04a642492b1
diff --git a/.skills/discourse-upcoming-changes-authoring/SKILL.md b/.skills/discourse-upcoming-changes-authoring/SKILL.mdindex ef915ee782c..d3edb58df37 100644--- a/.skills/discourse-upcoming-changes-authoring/SKILL.md+++ b/.skills/discourse-upcoming-changes-authoring/SKILL.md@@ -17,8 +17,8 @@ The upcoming changes system has three layers: a **Ruby core** that manages stateKey methods to understand:-- `resolved_value(setting_name)` — Determines the *effective* value of a setting. This is where auto-promotion logic lives: if a setting's status meets/exceeds `promote_upcoming_changes_on_status`, the resolved value is `true` even if the DB default is `false`. Permanent settings always resolve to `true` (admins can't disable them).-- `enabled_for_user?(setting_name, user)` — The primary access check. Considers: resolved value, group restrictions, anonymous users (only get access if no group restrictions).+- `enabled?(setting_name)` — Determines the *effective* value of a change. This is where auto-promotion logic lives: if a setting's status meets/exceeds `promote_upcoming_changes_on_status`, it resolves to `true` even if the DB default is `false`. Permanent settings always resolve to `true` (admins can't disable them). It returns `false` outright when the owning plugin is not configurable, or — for plugin-owned changes, unless they opt out with `requires_plugin_enabled: false` — when the owning plugin is disabled. Both take precedence over the above. See [Requiring the Owning Plugin](#requiring-the-owning-plugin).+- `enabled_for_user?(setting_name, user)` — The primary access check. Considers: the resolved value from `enabled?`, group restrictions, anonymous users (only get access if no group restrictions).- `stats_for_user(user:, acting_guardian:)` — Returns per-change status for a user including *why* they have/don't have access (the `user_enabled_reasons` enum).- `current_statuses` / `permanent_upcoming_changes` — Cached lookups keyed by git version (one-time cost per deploy). Cleared by `clear_caches!` and automatically when `TrackStatusChanges` detects changes.- `settings_hidden_while_enabled` — Returns the set of *other* site setting names that should be hidden from admins because an enabled change declares them in its `hide_settings:` metadata. Computed live (not toggled at opt-in time) so it tracks both opt-in paths and is multisite-safe. See [Hiding Settings While Enabled](#hiding-settings-while-enabled) below.@@ -142,14 +142,61 @@ Some upcoming changes only make sense to show admins under certain conditions#### How It Works1. **Filtering** — `UpcomingChanges::List#fetch_upcoming_changes` calls `UpcomingChanges::ConditionalDisplay.should_display?(setting_name)` on every change after the status filter, before group/image enrichment. Changes that return `false` are dropped from the result entirely.-2. **Resolution** — `should_display?` first checks for a class method named `should_display_<upcoming_change_name>?` on `ConditionalDisplay`. If defined, its return value is used. Otherwise it evaluates enabled plugin callbacks registered for that setting. If no method or callback is defined, the change is always displayed (returns `true`).+2. **Resolution** — `should_display?` first hides the change outright if its owning plugin is not configurable (`owning_plugin_configurable?`), or if it is plugin-owned and the owning plugin is disabled (`owning_plugin_enabled?`) — unless the change opts out with `requires_plugin_enabled: false`. Then it checks for a class method named `should_display_<upcoming_change_name>?` on `ConditionalDisplay`. If defined, its return value is used. Otherwise it evaluates enabled plugin callbacks registered for that setting. If no method or callback is defined, the change is always displayed (returns `true`).3. **Definition site** — Core gates can live directly on `ConditionalDisplay`, typically next to the relevant subsystem's code. Plugin gates should be registered from the plugin initializer via `register_upcoming_change_conditional_display(:setting_name) { ... }` so disabled plugins are filtered by `DiscoursePluginRegistry`.#### Key Behaviors-- **Display-only**: This affects whether the change appears in the admin UI list, not whether it's enabled. `enabled?` / `enabled_for_user?` still resolve normally — code paths gated on the change continue to work.+- **Display-only, with one exception**: A gate normally affects whether the change appears in the admin UI, not whether it's enabled — `enabled?` / `enabled_for_user?` still resolve normally, so code paths gated on the change continue to work. The exception is the owning-plugin checks, which `enabled?` consults too (see below).+- **Don't express the owning-plugin gate with a conditional display callback**: it's already the default for plugin-owned changes, and a callback couldn't express it anyway — `DiscoursePluginRegistry` filters callbacks from disabled plugins, so it would never run in the only case that matters. See [Requiring the Owning Plugin](#requiring-the-owning-plugin).- **N+1 by design**: `should_display?` is called once per change in the loop. If a gating method does expensive work (DB queries, plugin lookups), memoize inside the method to avoid repeated cost.-- **Notifications still fire**: Conditional display only filters the `List` service result. `TrackAddedChanges`, `NotifyAdminsOfAvailableUpcomingChanges`, `NotifyPromotions`, etc. do not consult `ConditionalDisplay`, so admins may still receive notifications about a hidden change. Consider this when designing the gate — usually the gate should reflect a long-lived condition (plugin missing, theme not installed) rather than transient state.+- **Notifications are gated too**: Beyond the `List` service, `NotifyAdminsOfAvailableUpcomingChanges` and `NotifyPromotion` also consult `should_display?`, so a hidden change is not notified about. `TrackAddedChanges` / `TrackRemovedChanges` do not — the audit trail records every change regardless. A gate should still reflect a long-lived condition (plugin missing, theme not installed) rather than transient state.++### Requiring the Owning Plugin++A plugin-owned change that gates a feature *inside* its plugin is useless while that plugin is disabled — the plugin's code isn't running, so the admin is being pitched (and notified about) a toggle that does nothing. This is the **default** for every plugin-owned change: no metadata is needed to get it.++```yaml+enable_your_plugin_feature:+ default: false+ client: true+ hidden: true+ upcoming_change:+ status: experimental+ impact: feature,all_members+ # requires_plugin_enabled defaults to true for plugin-owned changes -- nothing to add.+```++While the plugin is off, `UpcomingChanges.owning_plugin_enabled?` returns false, which both hides the change (`should_display?`) and stops it resolving (`enabled?`), so its `hide_settings` and default overrides don't apply either. The admin's opt-in stays in the database and resumes when they re-enable the plugin.++#### Opting out++Plenty of plugin-owned changes are the *opposite*: they exist to get the plugin adopted, and only make sense while it is disabled. Leaving one gated makes it unreachable — it would be hidden from exactly the sites it targets. These must opt out with `requires_plugin_enabled: false`:++```yaml+enable_your_plugin_feature:+ default: false+ client: true+ hidden: true+ upcoming_change:+ status: experimental+ impact: feature,all_members+ requires_plugin_enabled: false+```++Current examples, all of which set `requires_plugin_enabled: false`:++| Change | Why it must work with the plugin off |+|---|---|+| `enable_events_category_type_setup` (calendar), `enable_support_category_type_setup` (solved), `enable_ideas_category_type_setup` (topic-voting) | Offers a category type whose `enable_plugin` hook turns the plugin on when an admin picks it. Core registers category types *without* the plugin enabled — see `Categories::Types::Base#enable_plugin`. |+| `enable_discourse_reactions_by_default` (reactions) | An `upcoming_change_default_override` that flips `discourse_reactions_enabled` from `false` to `true`. Gating it on the plugin being enabled means it can never fire. |+| `enable_discourse_workflows` (workflows) | *Is* the plugin's `enabled_site_setting`. That row is how an admin opts into the plugin at all, so it *must* opt out — otherwise the default gate would gate the change on itself. |++Rule of thumb: if the change's purpose is *"try this feature we added to the plugin you already run"*, leave it gated (the default). If its purpose is *"start using this plugin"*, opt out with `false`.++#### Guardrails++The integrity spec (`spec/integrity/upcoming_change_metadata_spec.rb`) enforces that `requires_plugin_enabled`, when present, is a boolean and is only set on plugin-owned changes. It also **requires** a change that is its plugin's own `enabled_site_setting` to set `requires_plugin_enabled: false` — leaving the default gate on it would be self-gating and would recurse (`Plugin::Instance#enabled?` reads the setting, which resolves back through `enabled?`). `owning_plugin_enabled?` also guards against the recursion at runtime, so a mistake surfaces as a hidden change rather than a stack overflow. The spec derives ownership and the plugin's `enabled_site_setting` from the file path and `plugin.rb`, so it holds regardless of which plugins are loaded in the run.### CSS Opt-In@@ -331,6 +378,7 @@ To hide an upcoming change from the admin UI under certain conditions:SiteSetting.some_dependency_enabledend```+ The condition must be something *other* than the plugin's own `enabled_site_setting` — core already hides changes owned by a disabled plugin, and the registry would filter the callback out anyway.2. For core changes, reopen `UpcomingChanges::ConditionalDisplay` and define a class method named `should_display_<upcoming_change_name>?` that returns a boolean:```rubymodule UpcomingChangesdiff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rbindex 9a7b968351c..5aad8c07cef 100644--- a/lib/site_setting_extension.rb+++ b/lib/site_setting_extension.rb@@ -188,6 +188,12 @@ module SiteSettingExtension# Use for legacy settings that stop making sense once the change is in# effect. Hiding is computed per request so it is multisite-safe and# tracks both opt-in paths live. See UpcomingChanges.settings_hidden_while_enabled.+ # requires_plugin_enabled: (optional) boolean, defaults to true for plugin-owned+ # changes. By default a plugin-owned change is hidden from admins and does not+ # take effect while the owning plugin is disabled, since it gates a feature+ # inside the plugin. Set it to false to opt out -- for changes that exist to get+ # the plugin adopted (e.g. a category type that enables the plugin when chosen),+ # which must stay usable while the plugin is disabled.def upcoming_change_metadata@upcoming_change_metadata ||= {}enddiff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rbindex a94b6a8685b..8642e8bdc6f 100644--- a/lib/upcoming_changes.rb+++ b/lib/upcoming_changes.rb@@ -13,6 +13,10 @@ module UpcomingChanges# upcoming changes. If no conditional display rule is defined, the change will# always be displayed.#+ # A plugin-owned change is hidden, and never takes effect, while its owning+ # plugin is disabled -- unless it opts out with `requires_plugin_enabled: false`.+ # See .owning_plugin_enabled?+ ## Keep in mind this is called from UpcomingChanges::List service,# which loops over every change in an N1 depending on the filters admins# have selected, so caching may be appropriate at times.@@ -21,6 +25,7 @@ module UpcomingChangesupcoming_change_name = upcoming_change_name.to_symreturn false if !UpcomingChanges.owning_plugin_configurable?(upcoming_change_name)+ return false if !UpcomingChanges.owning_plugin_enabled?(upcoming_change_name)if respond_to?("should_display_#{upcoming_change_name}?")return public_send("should_display_#{upcoming_change_name}?")@@ -194,6 +199,33 @@ module UpcomingChangesDiscourse.plugins_by_name[plugin_name]&.configurable? != falseend+ # Whether a plugin-owned change is gated on the plugin being enabled.+ # By default: upcoming changes in plugins are neither displayed nor take effect.+ # A plugin change can opt OUT with `requires_plugin_enabled: false`.+ def self.requires_plugin_enabled?(change_setting_name)+ change_metadata(change_setting_name)[:requires_plugin_enabled] != false+ end++ def self.owning_plugin_enabled?(change_setting_name)+ change_setting_name = change_setting_name.to_sym+ return true if !requires_plugin_enabled?(change_setting_name)++ plugin_name = settings_provider.plugins[change_setting_name]+ return true if plugin_name.nil?++ plugin = Discourse.plugins_by_name[plugin_name]+ return true if plugin.nil?++ # Recursion guard: a change that is its own plugin's enabled_site_setting+ # must opt out with requires_plugin_enabled: false (enforced by the+ # integrity spec), but if that metadata is forgotten, plugin.enabled? below+ # would read the change setting, which resolves back through+ # UpcomingChanges.enabled? and recurses infinitely.+ return true if plugin.enabled_site_setting&.to_sym == change_setting_name++ plugin.enabled? != false+ end+# We dynamically determine if an upcoming change is enabled# or disabled based on the current status of the change as well# as whether the admin has manually toggled the change.@@ -212,6 +244,15 @@ module UpcomingChanges# a permanent change to an unavailable plugin still cannot take effect.return false if !owning_plugin_configurable?(change_setting_name)+ # The owning plugin is disabled, so the change must not take effect either.+ # Without this guard an opted-in change would keep acting on the site after+ # its plugin is switched off -- its `hide_settings` stay hidden and its+ # default overrides stay applied -- while ConditionalDisplay (which also+ # checks this) hides the change from admins, leaving them no way to see+ # what is causing those effects. The stored opt-in is deliberately left+ # untouched, so the change resumes when the plugin is re-enabled.+ return false if !owning_plugin_enabled?(change_setting_name)+# An admin has modified the setting and a value is stored# in the database, since the default for upcoming changes# is false.diff --git a/plugins/discourse-calendar/config/settings.yml b/plugins/discourse-calendar/config/settings.ymlindex 69341e922f8..5a00f844696 100644--- a/plugins/discourse-calendar/config/settings.yml+++ b/plugins/discourse-calendar/config/settings.yml@@ -140,6 +140,7 @@ discourse_calendar:status: "stable"impact: "feature,staff"learn_more_url: "https://meta.discourse.org/t/-/401309"+ requires_plugin_enabled: falselivestream_zoom_enabled:default: falseclient: truediff --git a/plugins/discourse-reactions/config/settings.yml b/plugins/discourse-reactions/config/settings.ymlindex 367d747d691..4f45024c0be 100644--- a/plugins/discourse-reactions/config/settings.yml+++ b/plugins/discourse-reactions/config/settings.yml@@ -43,6 +43,7 @@ discourse_reactions:impact: "site_setting_default,all_members"learn_more_url: "https://meta.discourse.org/t/-/403795"permanent_warning: false+ requires_plugin_enabled: falseenable_new_post_reply_count_position:default: falseclient: truediff --git a/plugins/discourse-solved/config/settings.yml b/plugins/discourse-solved/config/settings.ymlindex d375c23e682..99e97e4f9fb 100644--- a/plugins/discourse-solved/config/settings.yml+++ b/plugins/discourse-solved/config/settings.yml@@ -70,6 +70,9 @@ discourse_solved:status: "permanent"impact: "feature,staff"learn_more_url: "https://meta.discourse.org/t/-/398338"+ # Offers a category type that enables the plugin when chosen, so it must stay+ # usable while the plugin is disabled.+ requires_plugin_enabled: falseenable_solved_shared_issues:default: falsehidden: truediff --git a/plugins/discourse-topic-voting/config/settings.yml b/plugins/discourse-topic-voting/config/settings.ymlindex 67e67a7bad7..b1b3ddef9c4 100755--- a/plugins/discourse-topic-voting/config/settings.yml+++ b/plugins/discourse-topic-voting/config/settings.yml@@ -55,3 +55,4 @@ discourse_topic_voting:status: "stable"impact: "feature,staff"learn_more_url: "https://meta.discourse.org/t/-/399365"+ requires_plugin_enabled: falsediff --git a/plugins/discourse-workflows/config/settings.yml b/plugins/discourse-workflows/config/settings.ymlindex 43a73303c0d..90212170ca2 100644--- a/plugins/discourse-workflows/config/settings.yml+++ b/plugins/discourse-workflows/config/settings.yml@@ -9,6 +9,7 @@ plugins:learn_more_url: "https://meta.discourse.org/t/-/406990"allow_enabled_for:- everyone+ requires_plugin_enabled: falsediscourse_workflows_ai_authoring_enabled:default: falseclient: truediff --git a/spec/integrity/upcoming_change_metadata_spec.rb b/spec/integrity/upcoming_change_metadata_spec.rbindex 7209703f55c..689c0665b81 100644--- a/spec/integrity/upcoming_change_metadata_spec.rb+++ b/spec/integrity/upcoming_change_metadata_spec.rb@@ -39,6 +39,18 @@ def valid_upcoming_change_impact_roles%w[staff admins moderators all_members developers]end+# Derived from the file path rather than Discourse.plugins_by_name, so the checks+# hold regardless of which plugins happen to be loaded in the current test run.+def upcoming_change_owning_plugin_dir(setting)+ setting[:file][%r{plugins/([^/]+)/}, 1]+end++def upcoming_change_plugin_enabled_site_setting(plugin_dir)+ plugin_rb = Rails.root.join("plugins", plugin_dir, "plugin.rb")+ return nil unless File.exist?(plugin_rb)+ File.read(plugin_rb)[/enabled_site_setting\s+:(\w+)/, 1]&.to_sym+end+RSpec.describe "upcoming change metadata integrity checks" doeach_upcoming_change_setting do |setting|label = upcoming_change_setting_label(setting)@@ -53,6 +65,7 @@ RSpec.describe "upcoming change metadata integrity checks" dobody_classpermanent_warninghide_settings+ requires_plugin_enabled]required_keys = %i[status impact]unsupported_keys = metadata.keys - allowed_keys@@ -66,6 +79,12 @@ RSpec.describe "upcoming change metadata integrity checks" dobody_class = metadata[:body_class]permanent_warning = metadata[:permanent_warning]hide_settings = metadata[:hide_settings]+ requires_plugin_enabled = metadata[:requires_plugin_enabled]+ setting_name_sym = setting[:setting_name].to_sym+ owning_plugin_dir = upcoming_change_owning_plugin_dir(setting)+ is_own_enabled_site_setting =+ owning_plugin_dir.present? &&+ upcoming_change_plugin_enabled_site_setting(owning_plugin_dir) == setting_name_symaggregate_failures doexpect(setting[:options][:hidden]).to eq(true), "#{label} must set `hidden: true`"@@ -131,6 +150,24 @@ RSpec.describe "upcoming change metadata integrity checks" do"#{label} `upcoming_change.permanent_warning` must be a boolean"end+ unless requires_plugin_enabled.nil?+ expect([true, false]).to include(requires_plugin_enabled),+ "#{label} `upcoming_change.requires_plugin_enabled` must be a boolean"++ expect(owning_plugin_dir).to be_present,+ "#{label} sets `upcoming_change.requires_plugin_enabled` but is not owned by a plugin"+ end++ # Plugin-owned changes are gated on their plugin by default. A change that+ # is its plugin's own `enabled_site_setting` must opt out with+ # `requires_plugin_enabled: false`, otherwise the default gate would gate the+ # change on itself and it could never be reached (enabling it is how admins+ # turn the plugin on in the first place).+ if is_own_enabled_site_setting+ expect(requires_plugin_enabled).to eq(false),+ "#{label} is its plugin's own `enabled_site_setting` and must set `upcoming_change.requires_plugin_enabled: false`, otherwise the change gates itself"+ end+if hide_settings.present?expect(hide_settings).to be_an(Array),"#{label} `upcoming_change.hide_settings` must be an array"diff --git a/spec/lib/upcoming_changes_spec.rb b/spec/lib/upcoming_changes_spec.rbindex 712a46d2a0a..35b4e1a45d9 100644--- a/spec/lib/upcoming_changes_spec.rb+++ b/spec/lib/upcoming_changes_spec.rb@@ -3,6 +3,28 @@RSpec.describe UpcomingChanges dolet(:setting_name) { :enable_upload_debug_mode }+ # The sample plugin's change. Plugin-owned changes are gated on their owning+ # plugin being enabled by default, so this is gated unless it opts out below.+ def mock_plugin_change(status: :alpha, **extra)+ mock_upcoming_change_metadata(+ {+ enable_experimental_sample_plugin_feature: {+ impact: "feature,admins",+ status: status,+ impact_type: "feature",+ impact_role: "admins",+ **extra,+ },+ },+ )+ end++ # The same change, opted out of the owning-plugin gate with+ # requires_plugin_enabled: false, so it stays usable while the plugin is disabled.+ def mock_opted_out_plugin_change(status: :alpha, **extra)+ mock_plugin_change(status: status, requires_plugin_enabled: false, **extra)+ end+before domock_upcoming_change_metadata({@@ -425,6 +447,81 @@ RSpec.describe UpcomingChanges doendend+ describe ".owning_plugin_enabled?" do+ let(:plugin_setting_name) { :enable_experimental_sample_plugin_feature }++ after { UpcomingChanges.clear_caches! }++ it "returns true for a core change with no owning plugin" do+ expect(described_class.owning_plugin_enabled?(setting_name)).to eq(true)+ end++ context "when the change is gated on its plugin by default" do+ it "returns true when the owning plugin is enabled" do+ SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(true)++ expect(described_class.owning_plugin_enabled?(plugin_setting_name)).to eq(true)+ end++ it "returns false when the owning plugin is disabled" do+ SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(false)++ expect(described_class.owning_plugin_enabled?(plugin_setting_name)).to eq(false)+ end++ it "returns true when the owning plugin has not been loaded yet" do+ Discourse.stubs(:plugins_by_name).returns({})++ expect(described_class.owning_plugin_enabled?(plugin_setting_name)).to eq(true)+ end+ end++ context "when the change opts out with requires_plugin_enabled: false" do+ before { mock_opted_out_plugin_change }++ it "returns true even when the owning plugin is disabled" do+ SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(false)++ expect(described_class.owning_plugin_enabled?(plugin_setting_name)).to eq(true)+ end+ end++ context "when the change is the owning plugin's own enabled_site_setting" do+ # The integrity spec requires this change to opt out with+ # requires_plugin_enabled: false, but Plugin::Instance#enabled? reads the setting+ # back through .enabled?, so guard against the stack overflow even if it is left+ # gated. #enabled? reads the ivar directly, hence setting it rather than stubbing.+ before do+ SiteSetting::SAMPLE_TEST_PLUGIN.instance_variable_set(+ :@enabled_site_setting,+ plugin_setting_name,+ )+ end++ after do+ SiteSetting::SAMPLE_TEST_PLUGIN.instance_variable_set(:@enabled_site_setting, nil)+ SiteSetting.remove_override!(plugin_setting_name)+ UpcomingChanges.clear_caches!+ end++ it "returns true rather than recursing through Plugin::Instance#enabled?" do+ expect(described_class.owning_plugin_enabled?(plugin_setting_name)).to eq(true)+ end++ it "keeps the change displayed while the plugin is off, since that row is how admins opt in" do+ expect(UpcomingChanges::ConditionalDisplay.should_display?(plugin_setting_name)).to eq(true)+ end++ it "still resolves the change normally" do+ expect(described_class.enabled?(plugin_setting_name)).to eq(false)++ SiteSetting.enable_experimental_sample_plugin_feature = true++ expect(described_class.enabled?(plugin_setting_name)).to eq(true)+ end+ end+ end+describe ".enabled?" doafter doSiteSetting.remove_override!(setting_name)@@ -459,6 +556,51 @@ RSpec.describe UpcomingChanges doendend+ context "when the owning plugin is disabled" do+ let(:plugin_setting_name) { :enable_experimental_sample_plugin_feature }++ after do+ SiteSetting.remove_override!(plugin_setting_name)+ UpcomingChanges.clear_caches!+ end++ before { SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(false) }++ it "returns true when the change opts out with requires_plugin_enabled: false" do+ mock_opted_out_plugin_change+ SiteSetting.enable_experimental_sample_plugin_feature = true++ expect(described_class.enabled?(plugin_setting_name)).to eq(true)+ end++ it "returns false even when the admin has opted in" do+ SiteSetting.enable_experimental_sample_plugin_feature = true++ expect(described_class.enabled?(plugin_setting_name)).to eq(false)+ end++ it "returns false even when the change has been promoted" do+ SiteSetting.promote_upcoming_changes_on_status = :alpha++ expect(described_class.enabled?(plugin_setting_name)).to eq(false)+ end++ it "returns false even when the change is permanent" do+ mock_plugin_change(status: :permanent)++ expect(described_class.enabled?(plugin_setting_name)).to eq(false)+ end++ it "keeps the admin's opt-in, so the change resolves again once the plugin is enabled" do+ SiteSetting.enable_experimental_sample_plugin_feature = true+ expect(described_class.enabled?(plugin_setting_name)).to eq(false)++ SiteSetting::SAMPLE_TEST_PLUGIN.unstub(:enabled?)++ expect(described_class.enabled?(plugin_setting_name)).to eq(true)+ end+ end+context "when the change is not registered" doit "raises ArgumentError" doexpect { described_class.enabled?(:not_an_upcoming_change) }.to raise_error(@@ -706,6 +848,32 @@ RSpec.describe UpcomingChanges doexpect(described_class.settings_hidden_while_enabled).to be_emptyend+ context "when the change is owned by a plugin the admin has opted into and then disabled" do+ let(:plugin_setting_name) { :enable_experimental_sample_plugin_feature }++ before do+ mock_plugin_change(hide_settings: hidden_setting_names)+ SiteSetting.enable_experimental_sample_plugin_feature = true+ end++ after do+ SiteSetting.remove_override!(plugin_setting_name)+ UpcomingChanges.clear_caches!+ end++ it "hides the declared settings while the plugin is enabled" do+ expect(described_class.settings_hidden_while_enabled).to contain_exactly(+ *hidden_setting_names,+ )+ end++ it "stops hiding them once the plugin is disabled, so the change leaves nothing behind" do+ SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(false)++ expect(described_class.settings_hidden_while_enabled).to be_empty+ end+ end+it "feeds SiteSetting.hidden_settings so the settings are hidden while enabled" doexpect(SiteSetting.hidden_settings).not_to include(*hidden_setting_names)@@ -1046,6 +1214,40 @@ RSpec.describe UpcomingChanges do)end+ context "when the owning plugin is disabled" do+ let(:plugin_setting_name) { :enable_experimental_sample_plugin_feature }++ before { SiteSetting::SAMPLE_TEST_PLUGIN.stubs(:enabled?).returns(false) }++ after { UpcomingChanges.clear_caches! }++ it "hides the change by default" do+ expect(UpcomingChanges::ConditionalDisplay.should_display?(plugin_setting_name)).to eq(+ false,+ )+ end++ it "hides the change even when the plugin registered a conditional display callback" do+ SiteSetting::SAMPLE_TEST_PLUGIN.register_upcoming_change_conditional_display(+ plugin_setting_name,+ ) { true }++ expect(UpcomingChanges::ConditionalDisplay.should_display?(plugin_setting_name)).to eq(+ false,+ )+ end++ context "when the change opts out with requires_plugin_enabled: false" do+ before { mock_opted_out_plugin_change }++ it "still displays the change" do+ expect(UpcomingChanges::ConditionalDisplay.should_display?(plugin_setting_name)).to eq(+ true,+ )+ end+ end+ end+context "when the owning plugin is not configurable" dolet(:plugin_setting_name) { :enable_experimental_sample_plugin_feature }