A platform for community discussion. Free, open, simple.
FIX: Minor upcoming change bugs/edge cases (#37425)
Martin Brennaneffce878c510
diff --git a/app/services/upcoming_changes/notify_promotion.rb b/app/services/upcoming_changes/notify_promotion.rbindex 29f3f7fad29..7b788ba903e 100644--- a/app/services/upcoming_changes/notify_promotion.rb+++ b/app/services/upcoming_changes/notify_promotion.rb@@ -11,6 +11,8 @@## Admins will only be notified once for each upcoming change,# both via a staff action log and a Notification in the UI.+# We don't need to notify admins if they have manually opted in+# or out of the change, since that overrides the automatic promotion.class UpcomingChanges::NotifyPromotioninclude Service::Base@@ -26,7 +28,7 @@ class UpcomingChanges::NotifyPromotionpolicy :setting_is_availablepolicy :meets_or_exceeds_statuspolicy :change_has_not_already_been_notified_about_promotion- policy :admin_has_not_manually_opted_out+ policy :admin_has_not_manually_toggledtry dostep :log_promotion@@ -53,10 +55,8 @@ class UpcomingChanges::NotifyPromotion!params.changes_already_notified_about_promotion.include?(params.setting_name)end- def admin_has_not_manually_opted_out(params:)- # If they have opted out this will return false, since it will- # return true if the change has exceeded the promotion status.- UpcomingChanges.resolved_value(params.setting_name)+ def admin_has_not_manually_toggled(params:)+ !SiteSetting.modified.key?(params.setting_name)enddef log_promotion(params:, guardian:)diff --git a/app/services/upcoming_changes/notify_promotions.rb b/app/services/upcoming_changes/notify_promotions.rbindex 1246efea72b..250073aa47e 100644--- a/app/services/upcoming_changes/notify_promotions.rb+++ b/app/services/upcoming_changes/notify_promotions.rb@@ -55,8 +55,10 @@ class UpcomingChanges::NotifyPromotions] = "Setting #{setting_name} has already notified admins about promotion"end- on_failed_policy(:admin_has_not_manually_opted_out) do |policy|- status_hash[:error] = "Setting #{setting_name} has been manually opted out by an admin"+ on_failed_policy(:admin_has_not_manually_toggled) do |policy|+ status_hash[+ :error+ ] = "Setting #{setting_name} has been manually opted in or out by an admin, we did not notify admins about promotion"endon_exceptions do |exception|diff --git a/app/services/upcoming_changes/toggle.rb b/app/services/upcoming_changes/toggle.rbindex f5af747feda..57113b0c53f 100644--- a/app/services/upcoming_changes/toggle.rb+++ b/app/services/upcoming_changes/toggle.rb@@ -40,12 +40,13 @@ class UpcomingChanges::Toggleenddef toggle(params:, guardian:, options:)+ context[:previous_value] = SiteSetting.public_send(params.setting_name)+# TODO (martin) Remove this once we release upcoming changes,# otherwise it will be confusing for people to see log messages# about upcoming changes via "What's new?" experimental toggles# before we update that UI.if SiteSetting.enable_upcoming_changes- context[:previous_value] = SiteSetting.public_send(params.setting_name)SiteSetting.send("#{params.setting_name}=", params.enabled)elseSiteSetting.public_send("#{params.setting_name}=", params.enabled)diff --git a/frontend/discourse/admin/components/admin-config-areas/upcoming-changes.gjs b/frontend/discourse/admin/components/admin-config-areas/upcoming-changes.gjsindex d4f3845d18a..ed895c7420b 100644--- a/frontend/discourse/admin/components/admin-config-areas/upcoming-changes.gjs+++ b/frontend/discourse/admin/components/admin-config-areas/upcoming-changes.gjs@@ -1,4 +1,5 @@import Component from "@glimmer/component";+import { cached } from "@glimmer/tracking";import { array } from "@ember/helper";import { action } from "@ember/object";import { TrackedObject } from "@ember-compat/tracked-built-ins";@@ -8,6 +9,7 @@ import AdminFilterControls from "discourse/admin/components/admin-filter-controlimport { i18n } from "discourse-i18n";export default class AdminConfigAreasUpcomingChanges extends Component {+ @cachedget upcomingChanges() {return this.args.upcomingChanges.map((change) => {change.upcoming_change = new TrackedObject(change.upcoming_change);diff --git a/spec/services/upcoming_changes/notify_promotion_spec.rb b/spec/services/upcoming_changes/notify_promotion_spec.rbindex 06ed7ce5d78..5f210ffdf5d 100644--- a/spec/services/upcoming_changes/notify_promotion_spec.rb+++ b/spec/services/upcoming_changes/notify_promotion_spec.rb@@ -65,7 +65,13 @@ RSpec.describe UpcomingChanges::NotifyPromotion docontext "when admin has manually opted out" dobefore { SiteSetting.enable_upload_debug_mode = false }- it { is_expected.to fail_a_policy(:admin_has_not_manually_opted_out) }+ it { is_expected.to fail_a_policy(:admin_has_not_manually_toggled) }+ end++ context "when admin has manually opted in" do+ before { SiteSetting.enable_upload_debug_mode = true }++ it { is_expected.to fail_a_policy(:admin_has_not_manually_toggled) }endcontext "when everything's ok" dodiff --git a/spec/services/upcoming_changes/toggle_spec.rb b/spec/services/upcoming_changes/toggle_spec.rbindex a64565276ec..c5645dd01c9 100644--- a/spec/services/upcoming_changes/toggle_spec.rb+++ b/spec/services/upcoming_changes/toggle_spec.rb@@ -61,6 +61,17 @@ RSpec.describe UpcomingChanges::Toggle do}.by(1)end+ it "logs the correct previous value" do+ result+ history =+ UserHistory.find_by(+ action: UserHistory.actions[:change_site_setting],+ subject: "display_local_time_in_user_card",+ )+ expect(history.previous_value).to eq("false")+ expect(history.new_value).to eq("true")+ end+it "does not create an UpcomingChangeEvent" doexpect { result }.not_to change { UpcomingChangeEvent.count }end