A platform for community discussion. Free, open, simple.
UX: Consolidate upcoming change notifications for admins (#37976)
Martin Brennan0070b55cdf47
diff --git a/app/assets/stylesheets/common/base/menu-panel.scss b/app/assets/stylesheets/common/base/menu-panel.scssindex ec99f93ea2f..92ab6dd5571 100644--- a/app/assets/stylesheets/common/base/menu-panel.scss+++ b/app/assets/stylesheets/common/base/menu-panel.scss@@ -661,7 +661,7 @@overflow: hidden; // clears the text from wrapping below iconsoverflow-wrap: break-word;- @include line-clamp(2);+ @include line-clamp(3);}}diff --git a/app/services/upcoming_changes/action/notification_data_merger.rb b/app/services/upcoming_changes/action/notification_data_merger.rbnew file mode 100644index 00000000000..7df6044f920--- /dev/null+++ b/app/services/upcoming_changes/action/notification_data_merger.rb@@ -0,0 +1,36 @@+# frozen_string_literal: true++# Consolidates upcoming change notification data for both available and promoted changes.+# We do this so admins are not overwhelmed by many separate notifications for upcoming changes+# being available or promoted in cases like deployments where this is possible.+#+# Used in UpcomingChanges::Action::NotifyAdminsOfAvailableChange and UpcomingChanges::NotifyPromotion,+# and only unread notifications are considered for merging.+class UpcomingChanges::Action::NotificationDataMerger < Service::ActionBase+ option :existing_notification+ option :new_change_name++ def call+ if existing_notification+ existing_data = JSON.parse(existing_notification.data, symbolize_names: true)+ names =+ Array.wrap(existing_data[:upcoming_change_names] || [existing_data[:upcoming_change_name]])+ humanized =+ Array.wrap(+ existing_data[:upcoming_change_humanized_names] ||+ [existing_data[:upcoming_change_humanized_name]],+ )+ merged_names = (names.map(&:to_s) + [new_change_name.to_s]).uniq+ merged_humanized = (humanized + [SiteSetting.humanized_name(new_change_name)]).uniq+ else+ merged_names = [new_change_name.to_s]+ merged_humanized = [SiteSetting.humanized_name(new_change_name)]+ end++ {+ upcoming_change_names: merged_names,+ upcoming_change_humanized_names: merged_humanized,+ count: merged_names.size,+ }+ end+enddiff --git a/app/services/upcoming_changes/action/notify_admins_of_available_change.rb b/app/services/upcoming_changes/action/notify_admins_of_available_change.rbindex b48d15c2dff..99f3f958b94 100644--- a/app/services/upcoming_changes/action/notify_admins_of_available_change.rb+++ b/app/services/upcoming_changes/action/notify_admins_of_available_change.rb@@ -25,21 +25,36 @@ class UpcomingChanges::Action::NotifyAdminsOfAvailableChange < Service::ActionBaprivatedef notify_admins- data = {- upcoming_change_name: change_name,- upcoming_change_humanized_name: SiteSetting.humanized_name(change_name),- }.to_json+ existing_notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_available],+ user_id: all_admins.map(&:id),+ read: false,+ )+ existing_notification_rows = existing_notifications.to_a+ existing_by_user = existing_notification_rows.index_by(&:user_id)+ merge_with_existing = existing_notification_rows.present?- records =+ bulk_notification_new_records =all_admins.map do |admin|{user_id: admin.id,notification_type: Notification.types[:upcoming_change_available],- data:,+ data:+ UpcomingChanges::Action::NotificationDataMerger.call(+ existing_notification: existing_by_user[admin.id],+ new_change_name: change_name,+ ).to_json,}end- Notification::Action::BulkCreate.call(records:)+ Notification.transaction do+ existing_notifications.delete_all if merge_with_existing+ Notification::Action::BulkCreate.call(+ records: bulk_notification_new_records,+ skip_send_email: merge_with_existing,+ )+ endenddef create_eventdiff --git a/app/services/upcoming_changes/action/track_added_changes.rb b/app/services/upcoming_changes/action/track_added_changes.rbindex af751dd0c5c..5ab9c1dd6ad 100644--- a/app/services/upcoming_changes/action/track_added_changes.rb+++ b/app/services/upcoming_changes/action/track_added_changes.rb@@ -38,6 +38,9 @@ class UpcomingChanges::Action::TrackAddedChanges < Service::ActionBasechange_name,SiteSetting.promote_upcoming_changes_on_status.to_sym,)+ Rails.logger.info(+ "Notifying admins about available change #{change_name} from TrackAddedChanges",+ )notified =UpcomingChanges::Action::NotifyAdminsOfAvailableChange.call(change_name:, all_admins:)notified_changes << change_name if notifieddiff --git a/app/services/upcoming_changes/action/track_status_changes.rb b/app/services/upcoming_changes/action/track_status_changes.rbindex 804e0c47843..c4ce84b7d3a 100644--- a/app/services/upcoming_changes/action/track_status_changes.rb+++ b/app/services/upcoming_changes/action/track_status_changes.rb@@ -67,7 +67,14 @@ class UpcomingChanges::Action::TrackStatusChanges < Service::ActionBase# However, if the status was later changed and it meets the promotion status# minus one (previous status) criteria for notification, then we should notify# admins here.- if should_notify_admins?(change_name)+ if should_notify_admins?(change_name) &&+ !UpcomingChanges.meets_or_exceeds_status?(+ change_name,+ SiteSetting.promote_upcoming_changes_on_status.to_sym,+ )+ Rails.logger.info(+ "Notifying admins about available change #{change_name} from TrackStatusChanges",+ )notified =UpcomingChanges::Action::NotifyAdminsOfAvailableChange.call(change_name:, all_admins:)notified_changes << change_name if notifieddiff --git a/app/services/upcoming_changes/notify_promotion.rb b/app/services/upcoming_changes/notify_promotion.rbindex 7b788ba903e..c37d978d19f 100644--- a/app/services/upcoming_changes/notify_promotion.rb+++ b/app/services/upcoming_changes/notify_promotion.rb@@ -32,7 +32,8 @@ class UpcomingChanges::NotifyPromotiontry dostep :log_promotion- model :records+ model :existing_notifications, optional: true+ model :bulk_notification_new_recordsstep :notify_adminsstep :create_eventstep :trigger_discourse_event@@ -75,23 +76,39 @@ class UpcomingChanges::NotifyPromotion)end- def fetch_records(params:)- data = {- upcoming_change_name: params.setting_name,- upcoming_change_humanized_name: SiteSetting.humanized_name(params.setting_name),- }.to_json+ def fetch_existing_notifications(params:)+ Notification.where(+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ user_id: params.admin_user_ids,+ read: false,+ )+ end+ def fetch_bulk_notification_new_records(params:, existing_notifications:)+ existing_by_user = existing_notifications.to_a.index_by(&:user_id)params.admin_user_ids.map do |admin_id|{user_id: admin_id,notification_type: Notification.types[:upcoming_change_automatically_promoted],- data:,+ data:+ UpcomingChanges::Action::NotificationDataMerger.call(+ existing_notification: existing_by_user[admin_id],+ new_change_name: params.setting_name,+ ).to_json,}endend- def notify_admins(records:)- Notification::Action::BulkCreate.call(records:)+ def notify_admins(params:, bulk_notification_new_records:, existing_notifications:)+ merge_with_existing = existing_notifications.to_a.any?++ Notification.transaction do+ existing_notifications.delete_all if merge_with_existing+ Notification::Action::BulkCreate.call(+ records: bulk_notification_new_records,+ skip_send_email: merge_with_existing,+ )+ endenddef create_event(params:)diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex c6a584f69a2..2a3d366b49a 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3378,9 +3378,13 @@ en:available:title: "Upcoming changes"description: "'%{changeName}' is available for preview"+ description_two: "'%{changeName1}' and '%{changeName2}' are available for preview"+ description_many: "'%{changeName}' and %{otherChangeCount} more changes are available for preview"automatically_promoted:title: "Upcoming changes"description: "'%{changeName}' has been automatically enabled"+ description_two: "'%{changeName1}' and '%{changeName2}' were automatically enabled"+ description_many: "'%{changeName}' and %{otherChangeCount} more changes were automatically enabled"dismiss_confirmation:body:default:@@ -3442,8 +3446,8 @@ en:votes_released: "vote was released"new_features: "new discourse features have been released"admin_problems: "new advice on your site dashboard"- upcoming_change_available: "new upcoming change '%{changeName}' is available"- upcoming_change_automatically_promoted: "upcoming change '%{changeName}' has been automatically enabled"+ upcoming_change_available: "new upcoming changes are available"+ upcoming_change_automatically_promoted: "upcoming changes have been automatically enabled"upload_selector:change: "Change"diff --git a/frontend/discourse/app/lib/notification-types/upcoming-change-automatically-promoted.js b/frontend/discourse/app/lib/notification-types/upcoming-change-automatically-promoted.jsindex 3c169971a11..c516c63d5d4 100644--- a/frontend/discourse/app/lib/notification-types/upcoming-change-automatically-promoted.js+++ b/frontend/discourse/app/lib/notification-types/upcoming-change-automatically-promoted.js@@ -8,25 +8,46 @@ export default class extends NotificationTypeBase {}get linkTitle() {- return i18n("notifications.titles.upcoming_change_automatically_promoted", {- changeName: this.notification.data.upcoming_change_humanized_name,- });+ return i18n("notifications.titles.upcoming_change_automatically_promoted");}get description() {+ const data = this.notification.data;+ const names = data.upcoming_change_humanized_names || [+ data.upcoming_change_humanized_name,+ ];+ const count = data.count || names.length;++ if (count === 1) {+ return i18n(+ "notifications.upcoming_changes.automatically_promoted.description",+ { changeName: names[0] }+ );+ }++ if (count === 2) {+ return i18n(+ "notifications.upcoming_changes.automatically_promoted.description_two",+ { changeName1: names[0], changeName2: names[1] }+ );+ }+return i18n(- "notifications.upcoming_changes.automatically_promoted.description",- {- changeName: this.notification.data.upcoming_change_humanized_name,- }+ "notifications.upcoming_changes.automatically_promoted.description_many",+ { changeName: names[0], otherChangeCount: count - 1 });}get linkHref() {- return getURL("/admin/config/upcoming-changes");+ const data = this.notification.data;+ const names = data.upcoming_change_names || [data.upcoming_change_name];++ return getURL(+ `/admin/config/upcoming-changes?changeNamesFilter=${names.join(",")}`+ );}get icon() {- return "flask";+ return "discourse-flask-check";}}diff --git a/frontend/discourse/app/lib/notification-types/upcoming-change-available.js b/frontend/discourse/app/lib/notification-types/upcoming-change-available.jsindex a63775fb309..84edfa51ac3 100644--- a/frontend/discourse/app/lib/notification-types/upcoming-change-available.js+++ b/frontend/discourse/app/lib/notification-types/upcoming-change-available.js@@ -8,19 +8,42 @@ export default class extends NotificationTypeBase {}get linkTitle() {- return i18n("notifications.titles.upcoming_change_available", {- changeName: this.notification.data.upcoming_change_humanized_name,- });+ return i18n("notifications.titles.upcoming_change_available");}get description() {- return i18n("notifications.upcoming_changes.available.description", {- changeName: this.notification.data.upcoming_change_humanized_name,+ const data = this.notification.data;+ const names = data.upcoming_change_humanized_names || [+ data.upcoming_change_humanized_name,+ ];+ const count = data.count || names.length;++ if (count === 1) {+ return i18n("notifications.upcoming_changes.available.description", {+ changeName: names[0],+ });+ }++ if (count === 2) {+ return i18n("notifications.upcoming_changes.available.description_two", {+ changeName1: names[0],+ changeName2: names[1],+ });+ }++ return i18n("notifications.upcoming_changes.available.description_many", {+ changeName: names[0],+ otherChangeCount: count - 1,});}get linkHref() {- return getURL("/admin/config/upcoming-changes");+ const data = this.notification.data;+ const names = data.upcoming_change_names || [data.upcoming_change_name];++ return getURL(+ `/admin/config/upcoming-changes?changeNamesFilter=${names.join(",")}`+ );}get icon() {diff --git a/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-automatically-promoted-test.js b/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-automatically-promoted-test.jsnew file mode 100644index 00000000000..72eeda2bf76--- /dev/null+++ b/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-automatically-promoted-test.js@@ -0,0 +1,162 @@+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import Notification from "discourse/models/notification";+import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper";+import { i18n } from "discourse-i18n";++function getNotification(data) {+ return Notification.create({+ id: 1,+ user_id: 1,+ notification_type: 42,+ read: false,+ high_priority: false,+ created_at: "2025-01-01T00:00:00.000Z",+ data: data || {+ upcoming_change_names: ["Enable Feature X"],+ upcoming_change_humanized_names: ["Enable Feature X"],+ count: 1,+ },+ });+}++module(+ "Unit | Notification Types | upcoming-change-automatically-promoted",+ function (hooks) {+ setupTest(hooks);++ test("description with single change", function (assert) {+ const notification = getNotification();+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n(+ "notifications.upcoming_changes.automatically_promoted.description",+ { changeName: "Enable Feature X" }+ )+ );+ });++ test("description with two changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: ["enable_feature_x", "enable_feature_y"],+ upcoming_change_humanized_names: [+ "Enable Feature X",+ "Enable Feature Y",+ ],+ count: 2,+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n(+ "notifications.upcoming_changes.automatically_promoted.description_two",+ {+ changeName1: "Enable Feature X",+ changeName2: "Enable Feature Y",+ }+ )+ );+ });++ test("description with many changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: [+ "enable_feature_x",+ "enable_feature_y",+ "enable_feature_z",+ "enable_feature_w",+ ],+ upcoming_change_humanized_names: [+ "Enable Feature X",+ "Enable Feature Y",+ "Enable Feature Z",+ "Enable Feature W",+ ],+ count: 4,+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n(+ "notifications.upcoming_changes.automatically_promoted.description_many",+ { changeName: "Enable Feature X", otherChangeCount: 3 }+ )+ );+ });++ test("description with old singular data format", function (assert) {+ const notification = getNotification({+ upcoming_change_humanized_name: "Enable Feature X",+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n(+ "notifications.upcoming_changes.automatically_promoted.description",+ { changeName: "Enable Feature X" }+ )+ );+ });++ test("linkHref with a single change", function (assert) {+ const notification = getNotification({+ upcoming_change_names: ["enable_feature_x"],+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.linkHref,+ "/admin/config/upcoming-changes?changeNamesFilter=enable_feature_x"+ );+ });++ test("linkHref with multiple changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: [+ "enable_feature_x",+ "enable_feature_y",+ "enable_feature_z",+ ],+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(+ director.linkHref,+ "/admin/config/upcoming-changes?changeNamesFilter=enable_feature_x,enable_feature_y,enable_feature_z"+ );+ });++ test("icon", function (assert) {+ const notification = getNotification();+ const director = createRenderDirector(+ notification,+ "upcoming_change_automatically_promoted",+ this.siteSettings+ );+ assert.strictEqual(director.icon, "discourse-flask-check");+ });+ }+);diff --git a/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-available-test.js b/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-available-test.jsnew file mode 100644index 00000000000..475cc429390--- /dev/null+++ b/frontend/discourse/tests/unit/lib/notification-types/upcoming-change-available-test.js@@ -0,0 +1,157 @@+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import Notification from "discourse/models/notification";+import { createRenderDirector } from "discourse/tests/helpers/notification-types-helper";+import { i18n } from "discourse-i18n";++function getNotification(data) {+ return Notification.create({+ id: 1,+ user_id: 1,+ notification_type: 41,+ read: false,+ high_priority: false,+ created_at: "2025-01-01T00:00:00.000Z",+ data: data || {+ upcoming_change_names: ["Enable Feature X"],+ upcoming_change_humanized_names: ["Enable Feature X"],+ count: 1,+ },+ });+}++module(+ "Unit | Notification Types | upcoming-change-available",+ function (hooks) {+ setupTest(hooks);++ test("description with single change", function (assert) {+ const notification = getNotification();+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n("notifications.upcoming_changes.available.description", {+ changeName: "Enable Feature X",+ })+ );+ });++ test("description with two changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: ["enable_feature_x", "enable_feature_y"],+ upcoming_change_humanized_names: [+ "Enable Feature X",+ "Enable Feature Y",+ ],+ count: 2,+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n("notifications.upcoming_changes.available.description_two", {+ changeName1: "Enable Feature X",+ changeName2: "Enable Feature Y",+ })+ );+ });++ test("description with many changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: [+ "enable_feature_x",+ "enable_feature_y",+ "enable_feature_z",+ "enable_feature_w",+ ],+ upcoming_change_humanized_names: [+ "Enable Feature X",+ "Enable Feature Y",+ "Enable Feature Z",+ "Enable Feature W",+ ],+ count: 4,+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n("notifications.upcoming_changes.available.description_many", {+ changeName: "Enable Feature X",+ otherChangeCount: 3,+ })+ );+ });++ test("description with old singular data format", function (assert) {+ const notification = getNotification({+ upcoming_change_humanized_name: "Enable Feature X",+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.description,+ i18n("notifications.upcoming_changes.available.description", {+ changeName: "Enable Feature X",+ })+ );+ });++ test("linkHref with a single change", function (assert) {+ const notification = getNotification({+ upcoming_change_names: ["enable_feature_x"],+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.linkHref,+ "/admin/config/upcoming-changes?changeNamesFilter=enable_feature_x"+ );+ });++ test("linkHref with multiple changes", function (assert) {+ const notification = getNotification({+ upcoming_change_names: [+ "enable_feature_x",+ "enable_feature_y",+ "enable_feature_z",+ ],+ });+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(+ director.linkHref,+ "/admin/config/upcoming-changes?changeNamesFilter=enable_feature_x,enable_feature_y,enable_feature_z"+ );+ });++ test("icon", function (assert) {+ const notification = getNotification();+ const director = createRenderDirector(+ notification,+ "upcoming_change_available",+ this.siteSettings+ );+ assert.strictEqual(director.icon, "flask");+ });+ }+);diff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rbindex 6552c01f514..4c866d6a813 100644--- a/lib/svg_sprite.rb+++ b/lib/svg_sprite.rb@@ -90,6 +90,7 @@ module SvgSpritediscourse-dnddiscourse-emojisdiscourse-expand+ discourse-flask-checkdiscourse-other-tabdiscourse-sidebardiscourse-sparklesdiff --git a/spec/services/upcoming_changes/action/notify_admins_of_available_change_spec.rb b/spec/services/upcoming_changes/action/notify_admins_of_available_change_spec.rbindex 3e7de48fecf..31ee71c361d 100644--- a/spec/services/upcoming_changes/action/notify_admins_of_available_change_spec.rb+++ b/spec/services/upcoming_changes/action/notify_admins_of_available_change_spec.rb@@ -12,6 +12,12 @@ RSpec.describe UpcomingChanges::Action::NotifyAdminsOfAvailableChange doimpact_type: "feature",impact_role: "all_members",},+ test_upcoming_change_b: {+ impact: "feature,all_members",+ status: :beta,+ impact_type: "feature",+ impact_role: "all_members",+ },},)end@@ -40,13 +46,15 @@ RSpec.describe UpcomingChanges::Action::NotifyAdminsOfAvailableChange do}.by(2)end- it "creates notifications with correct data" do+ it "creates notifications with array data format" doresult- expect(JSON.parse(notification.data)).to include(- "upcoming_change_name" => "test_upcoming_change",- "upcoming_change_humanized_name" => SiteSetting.humanized_name(:test_upcoming_change),+ data = JSON.parse(notification.data)+ expect(data["upcoming_change_names"]).to eq(["test_upcoming_change"])+ expect(data["upcoming_change_humanized_names"]).to eq(+ [SiteSetting.humanized_name(:test_upcoming_change)],)+ expect(data["count"]).to eq(1)endit "creates an admins_notified_available_change event" do@@ -66,5 +74,150 @@ RSpec.describe UpcomingChanges::Action::NotifyAdminsOfAvailableChange do).count}.by(1)end++ context "when there is an existing unread notification" do+ before do+ Fabricate(+ :notification,+ user: admin_1,+ notification_type: Notification.types[:upcoming_change_available],+ read: false,+ data: {+ upcoming_change_names: ["test_upcoming_change_b"],+ upcoming_change_humanized_names: [SiteSetting.humanized_name(:test_upcoming_change_b)],+ count: 1,+ }.to_json,+ )+ end++ it "skips sending email when consolidating notifications" do+ allow(Notification::Action::BulkCreate).to receive(:call).and_call_original++ result++ expect(Notification::Action::BulkCreate).to have_received(:call).with(+ satisfy { |args| args[:skip_send_email] == true },+ )+ end++ it "consolidates into a single notification per admin" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_available],+ user_id: admin_1.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to contain_exactly(+ "test_upcoming_change_b",+ "test_upcoming_change",+ )+ expect(data["count"]).to eq(2)+ end+ end++ context "when there is an existing read notification" do+ before do+ Fabricate(+ :notification,+ user: admin_1,+ notification_type: Notification.types[:upcoming_change_available],+ read: true,+ data: {+ upcoming_change_names: ["test_upcoming_change_b"],+ upcoming_change_humanized_names: [SiteSetting.humanized_name(:test_upcoming_change_b)],+ count: 1,+ }.to_json,+ )+ end++ it "does not skip sending email when not consolidating notifications" do+ allow(Notification::Action::BulkCreate).to receive(:call).and_call_original++ result++ expect(Notification::Action::BulkCreate).to have_received(:call).with(+ satisfy { |args| args[:skip_send_email] == false },+ )+ end++ it "does not consolidate with the read notification" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_available],+ user_id: admin_1.id,+ )+ expect(notifications.count).to eq(2)+ end+ end++ context "when the same change is already in an unread notification" do+ before do+ Fabricate(+ :notification,+ user: admin_1,+ notification_type: Notification.types[:upcoming_change_available],+ read: false,+ data: {+ upcoming_change_names: ["test_upcoming_change"],+ upcoming_change_humanized_names: [SiteSetting.humanized_name(:test_upcoming_change)],+ count: 1,+ }.to_json,+ )+ end++ it "deduplicates the change names" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_available],+ user_id: admin_1.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to eq(["test_upcoming_change"])+ expect(data["count"]).to eq(1)+ end+ end++ context "when there is an existing notification with the old data format" do+ before do+ Fabricate(+ :notification,+ user: admin_1,+ notification_type: Notification.types[:upcoming_change_available],+ read: false,+ data: {+ upcoming_change_name: "test_upcoming_change_b",+ upcoming_change_humanized_name: SiteSetting.humanized_name(:test_upcoming_change_b),+ }.to_json,+ )+ end++ it "merges old format into the new array format" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_available],+ user_id: admin_1.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to contain_exactly(+ "test_upcoming_change_b",+ "test_upcoming_change",+ )+ expect(data["count"]).to eq(2)+ end+ endendenddiff --git a/spec/services/upcoming_changes/action/track_status_changes_spec.rb b/spec/services/upcoming_changes/action/track_status_changes_spec.rbindex fc6ba4d3c03..08901cb4a34 100644--- a/spec/services/upcoming_changes/action/track_status_changes_spec.rb+++ b/spec/services/upcoming_changes/action/track_status_changes_spec.rb@@ -314,5 +314,42 @@ RSpec.describe UpcomingChanges::Action::TrackStatusChanges doendendend++ context "when a change jumps directly to the promotion status" do+ let(:show_user_menu_avatars_status) { :stable }++ before do+ SiteSetting.promote_upcoming_changes_on_status = "stable"+ UpcomingChangeEvent.create!(+ event_type: :status_changed,+ upcoming_change_name: :show_user_menu_avatars,+ event_data: {+ "previous_value" => nil,+ "new_value" => "experimental",+ },+ )+ UpcomingChangeEvent.create!(+ event_type: :status_changed,+ upcoming_change_name: :enable_upload_debug_mode,+ event_data: {+ "previous_value" => nil,+ "new_value" => "experimental",+ },+ )+ end++ it "does not send an upcoming_change_available notification" do+ expect { result }.not_to change {+ Notification+ .where(notification_type: Notification.types[:upcoming_change_available])+ .where("data::text LIKE ?", "%show_user_menu_avatars%")+ .count+ }+ end++ it "does not include the change in notified_changes" do+ expect(result[:notified_changes]).not_to include(:show_user_menu_avatars)+ end+ endendenddiff --git a/spec/services/upcoming_changes/notify_promotion_spec.rb b/spec/services/upcoming_changes/notify_promotion_spec.rbindex 5f210ffdf5d..67b87f1b22f 100644--- a/spec/services/upcoming_changes/notify_promotion_spec.rb+++ b/spec/services/upcoming_changes/notify_promotion_spec.rb@@ -116,12 +116,10 @@ RSpec.describe UpcomingChanges::NotifyPromotion do.count}.by(2)- expect(notification.data).to eq(- {- upcoming_change_name: :enable_upload_debug_mode,- upcoming_change_humanized_name: "Enable upload debug mode",- }.to_json,- )+ data = JSON.parse(notification.data)+ expect(data["upcoming_change_names"]).to eq(["enable_upload_debug_mode"])+ expect(data["upcoming_change_humanized_names"]).to eq(["Enable upload debug mode"])+ expect(data["count"]).to eq(1)endit "creates an admins_notified_automatic_promotion event" do@@ -136,6 +134,151 @@ RSpec.describe UpcomingChanges::NotifyPromotion doit "triggers DiscourseEvent for the promoted setting" doexpect(event[:params]).to eq([:enable_upload_debug_mode])end++ context "when there is an existing unread notification" do+ before do+ Fabricate(+ :notification,+ user: admin,+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ read: false,+ data: {+ upcoming_change_names: ["other_change"],+ upcoming_change_humanized_names: ["Other change"],+ count: 1,+ }.to_json,+ )+ end++ it "skips sending email when consolidating notifications" do+ allow(Notification::Action::BulkCreate).to receive(:call).and_call_original++ result++ expect(Notification::Action::BulkCreate).to have_received(:call).with(+ satisfy { |args| args[:skip_send_email] == true },+ )+ end++ it "consolidates into a single notification per admin" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ user_id: admin.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to contain_exactly(+ "other_change",+ "enable_upload_debug_mode",+ )+ expect(data["count"]).to eq(2)+ end+ end++ context "when there is an existing read notification" do+ before do+ Fabricate(+ :notification,+ user: admin,+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ read: true,+ data: {+ upcoming_change_names: ["other_change"],+ upcoming_change_humanized_names: ["Other change"],+ count: 1,+ }.to_json,+ )+ end++ it "does not skip sending email when not consolidating notifications" do+ allow(Notification::Action::BulkCreate).to receive(:call).and_call_original++ result++ expect(Notification::Action::BulkCreate).to have_received(:call).with(+ satisfy { |args| args[:skip_send_email] == false },+ )+ end++ it "does not consolidate with the read notification" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ user_id: admin.id,+ )+ expect(notifications.count).to eq(2)+ end+ end++ context "when the same change is already in an unread notification" do+ before do+ Fabricate(+ :notification,+ user: admin,+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ read: false,+ data: {+ upcoming_change_names: ["enable_upload_debug_mode"],+ upcoming_change_humanized_names: ["Enable upload debug mode"],+ count: 1,+ }.to_json,+ )+ end++ it "deduplicates the change names" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ user_id: admin.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to eq(["enable_upload_debug_mode"])+ expect(data["count"]).to eq(1)+ end+ end++ context "when there is an existing notification with the old data format" do+ before do+ Fabricate(+ :notification,+ user: admin,+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ read: false,+ data: {+ upcoming_change_name: "other_change",+ upcoming_change_humanized_name: "Other change",+ }.to_json,+ )+ end++ it "merges old format into the new array format" do+ result++ notifications =+ Notification.where(+ notification_type: Notification.types[:upcoming_change_automatically_promoted],+ user_id: admin.id,+ )+ expect(notifications.count).to eq(1)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to contain_exactly(+ "other_change",+ "enable_upload_debug_mode",+ )+ expect(data["count"]).to eq(2)+ end+ endendendenddiff --git a/spec/services/upcoming_changes/notify_promotions_spec.rb b/spec/services/upcoming_changes/notify_promotions_spec.rbindex 9155a8eee07..4466f55ac32 100644--- a/spec/services/upcoming_changes/notify_promotions_spec.rb+++ b/spec/services/upcoming_changes/notify_promotions_spec.rb@@ -104,12 +104,10 @@ RSpec.describe UpcomingChanges::NotifyPromotions do}.by(2)notification = Notification.where("data::text LIKE ?", "%enable_upload_debug_mode%").last- expect(notification.data).to eq(- {- upcoming_change_name: :enable_upload_debug_mode,- upcoming_change_humanized_name: "Enable upload debug mode",- }.to_json,- )+ data = JSON.parse(notification.data)+ expect(data["upcoming_change_names"]).to eq(["enable_upload_debug_mode"])+ expect(data["upcoming_change_humanized_names"]).to eq(["Enable upload debug mode"])+ expect(data["count"]).to eq(1)endit "creates an admins_notified_automatic_promotion event" do@@ -136,13 +134,22 @@ RSpec.describe UpcomingChanges::NotifyPromotions docontext "when multiple settings meet promotion criteria" dolet(:show_user_menu_avatars_status) { :stable }- it "processes all eligible settings" do- expect { result }.to change {+ it "processes all eligible settings into consolidated notifications" do+ result++ notifications =Notification.where(notification_type: Notification.types[:upcoming_change_automatically_promoted],user_id: [admin.id, admin_2.id],- ).count- }.by(4)+ )+ expect(notifications.count).to eq(2)++ data = JSON.parse(notifications.first.data)+ expect(data["upcoming_change_names"]).to contain_exactly(+ "enable_upload_debug_mode",+ "show_user_menu_avatars",+ )+ expect(data["count"]).to eq(2)endit "creates events for all promoted settings" dodiff --git a/vendor/assets/svg-icons/discourse-additional.svg b/vendor/assets/svg-icons/discourse-additional.svgindex 440146b645e..34217c123c1 100644--- a/vendor/assets/svg-icons/discourse-additional.svg+++ b/vendor/assets/svg-icons/discourse-additional.svg@@ -106,7 +106,6 @@ Additional SVG icons<path d="M0.778442 0C0.155688 0 0 0.66007 0 0.990106V2.57251C0 3.85876 1.715 3.85876 1.715 2.57251C1.715 1.28625 1.715 1.715 1.715 1.715H4.21453V10.5513H2.62724C1.89745 10.5513 1.84272 12.4338 2.57251 12.4338H7.30397C8.03376 12.4338 8.08849 10.5513 7.35871 10.5513H5.77141V1.715H8.57502V2.57251C8.57502 3.85876 10.29 3.70423 10.29 2.57251V0.857502C10.29 0.527467 9.83026 0 9.2075 0H0.778442Z"/></symbol><symbol id="discourse-h1" viewBox="0 0 700 500"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 608.204 130.88 C 608.204 121.152 602.845 112.249 594.272 107.633 C 585.698 103.016 575.311 103.511 567.232 108.952 L 488.091 161.712 C 475.891 169.791 472.676 186.113 480.754 198.314 C 488.833 210.515 505.239 213.73 517.357 205.651 L 555.443 180.178 L 555.443 421.062 L 502.683 421.062 C 488.091 421.062 476.303 432.85 476.303 447.442 C 476.303 462.033 488.091 473.822 502.683 473.822 L 581.823 473.822 L 660.964 473.822 C 675.555 473.822 687.344 462.033 687.344 447.442 C 687.344 432.85 675.555 421.062 660.964 421.062 L 608.204 421.062 L 608.204 130.88 Z" /></symbol>-<symbol id="discourse-h2" viewBox="0 0 700 500"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 571.552 176.628 C 557.109 176.628 543.202 183.2 532.991 195.029 L 512.232 218.84 C 503.834 228.505 490.197 228.505 481.8 218.84 C 473.402 209.177 473.402 193.482 481.8 183.819 L 502.558 160.006 C 520.899 138.977 545.688 127.149 571.552 127.149 C 625.363 127.149 669.03 177.402 669.03 239.326 C 669.03 269.092 658.752 297.62 640.479 318.649 L 548.98 424.026 L 669.03 424.026 C 680.921 424.026 690.528 435.08 690.528 448.765 C 690.528 462.449 680.921 473.505 669.03 473.505 L 497.049 473.505 C 488.383 473.505 480.523 467.475 477.164 458.198 C 473.805 448.919 475.686 438.328 481.8 431.215 L 610.047 283.704 C 620.258 271.952 626.035 255.949 626.035 239.326 C 626.035 204.693 601.649 176.628 571.552 176.628 Z" /></symbol><symbol viewBox="0 0 700 500" id="discourse-h3"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 473.255 156.521 C 473.255 143.016 482.923 132.105 494.892 132.105 L 657.172 132.105 C 666.097 132.105 674.076 138.286 677.322 147.67 C 680.568 157.055 678.336 167.737 671.777 174.529 L 582.996 266.398 L 597.669 266.398 C 648.45 266.398 689.628 312.865 689.628 370.167 C 689.628 427.47 648.45 473.937 597.669 473.937 L 544.522 473.937 C 515.853 473.937 489.617 455.624 476.839 426.706 L 475.554 423.807 C 470.212 411.752 474.54 397.102 485.222 391.074 C 495.906 385.046 508.889 389.928 514.23 401.985 L 515.515 404.885 C 520.993 417.321 532.284 425.104 544.522 425.104 L 597.669 425.104 C 624.581 425.104 646.353 400.536 646.353 370.167 C 646.353 339.8 624.581 315.23 597.669 315.23 L 527.348 315.23 C 518.423 315.23 510.444 309.05 507.198 299.666 C 503.952 290.281 506.184 279.599 512.743 272.807 L 601.524 180.937 L 494.892 180.937 C 482.923 180.937 473.255 170.026 473.255 156.521 Z" /></symbol><symbol id="discourse-h4" viewBox="0 0 700 500"><path d="M 15.445 57.815 C 15.445 40.115 29.745 25.815 47.445 25.815 L 95.445 25.815 L 143.445 25.815 C 161.145 25.815 175.445 40.115 175.445 57.815 C 175.445 75.515 161.145 89.815 143.445 89.815 L 127.445 89.815 L 127.445 201.816 L 351.445 201.816 L 351.445 89.815 L 335.445 89.815 C 317.745 89.815 303.445 75.515 303.445 57.815 C 303.445 40.115 317.745 25.815 335.445 25.815 L 383.445 25.815 L 431.445 25.815 C 449.145 25.815 463.445 40.115 463.445 57.815 C 463.445 75.515 449.145 89.815 431.445 89.815 L 415.445 89.815 L 415.445 233.816 L 415.445 409.816 L 431.445 409.816 C 449.145 409.816 463.445 424.116 463.445 441.816 C 463.445 459.516 449.145 473.816 431.445 473.816 L 383.445 473.816 L 335.445 473.816 C 317.745 473.816 303.445 459.516 303.445 441.816 C 303.445 424.116 317.745 409.816 335.445 409.816 L 351.445 409.816 L 351.445 265.816 L 127.445 265.816 L 127.445 409.816 L 143.445 409.816 C 161.145 409.816 175.445 424.116 175.445 441.816 C 175.445 459.516 161.145 473.816 143.445 473.816 L 95.445 473.816 L 47.445 473.816 C 29.745 473.816 15.445 459.516 15.445 441.816 C 15.445 424.116 29.745 409.816 47.445 409.816 L 63.445 409.816 L 63.445 233.816 L 63.445 89.815 L 47.445 89.815 C 29.745 89.815 15.445 75.515 15.445 57.815 Z" /><path d="M 575.204 170.97 C 579.64 158.991 575.619 144.692 566.157 139.076 C 556.694 133.461 545.399 138.551 540.963 150.531 L 465.204 354.242 C 462.425 361.654 462.898 370.34 466.328 377.302 C 469.758 384.264 475.85 388.382 482.355 388.382 L 614.829 388.382 L 614.829 448.275 C 614.829 461.527 623.286 472.233 633.754 472.233 C 644.222 472.233 652.678 461.527 652.678 448.275 L 652.678 388.382 L 671.603 388.382 C 682.071 388.382 690.528 377.676 690.528 364.424 C 690.528 351.172 682.071 340.468 671.603 340.468 L 652.678 340.468 L 652.678 232.659 C 652.678 219.407 644.222 208.704 633.754 208.704 C 623.286 208.704 614.829 219.407 614.829 232.659 L 614.829 340.468 L 512.161 340.468 L 575.204 170.97 Z" /></symbol>@@ -118,7 +117,6 @@ Additional SVG icons<use href="#plus" transform="translate(256 256) scale(0.9) translate(-256 -256)" /></g></symbol>-<symbol id="table-cells-minus" viewBox="0 0 512 512"><use href="#table-cells"/><g transform="translate(220, 220) scale(0.7)">@@ -126,4 +124,9 @@ Additional SVG icons<use href="#minus" transform="translate(256 256) scale(0.9) translate(-256 -256)" /></g></symbol>+ <!-- Discourse Flask Check" is a Discourse derivative of https://fontawesome.com/icons/flask and https://fontawesome.com/icons/check -->+ <symbol id="discourse-flask-check" viewBox="0 0 448 512">+ <path d="M320 64c17.46 0 31.61-13.91 31.99-31.28C352.39 14.73 337.24 0 319.24 0H128.76c-18 0-33.15 14.73-32.75 32.72.38 17.35 14.51 31.25 31.95 31.28.02 0 .04.02.04.04v151.47L7.5 426.3C2.04 436-.57 446.94.1 458.15 1.91 488.56 27.72 512 58.19 512H390.7c31.6 0 57.3-25.6 57.3-57.3 0-10-2.6-19.8-7.5-28.4l-51.88-85.77A42.57 42.57 0 0 0 352.21 320H142.07s-.05-.03-.04-.06l41.57-72.64c5.5-9.7 8.4-20.6 8.4-31.8V64.04s.02-.04.04-.04H256"/>+ <path d="m433.8 70.76-2.01 2.74 1.98-2.73c-13.68-9.91-32.95-6.9-42.98 6.72l-77.76 106.87-36.49-36.44c-11.96-11.9-31.43-11.9-43.41.02-11.87 11.95-11.87 31.4.02 43.37l61.86 61.81c5.83 5.72 13.64 8.89 21.68 8.89.79 0 1.58-.03 2.38-.09 9.04-.59 17.27-5.14 22.55-12.46l98.87-135.85c9.96-13.61 6.96-32.83-6.69-42.84Z"/>+ </symbol></svg>