Skip to content

A platform for community discussion. Free, open, simple.

UX: Allow admins to opt out of upcoming change available notifications (#40020)

Martin Brennan0c46a2e805ae
diff --git a/app/models/user_option.rb b/app/models/user_option.rb
index b23c5b9c83f..b0ec5189d51 100644
--- a/app/models/user_option.rb
+++ b/app/models/user_option.rb
@@ -263,76 +263,77 @@ end
#
# Table name: user_options
#
-# ai_search_discoveries :boolean default(TRUE), not null
-# allow_private_messages :boolean default(TRUE), not null
-# auto_image_caption :boolean default(FALSE), not null
-# auto_track_topics_after_msecs :integer
-# automatically_unpin_topics :boolean default(TRUE), not null
-# bookmark_auto_delete_preference :integer default(3), not null
-# chat_email_frequency :integer default("when_away"), not null
-# chat_enabled :boolean default(TRUE), not null
-# chat_header_indicator_preference :integer default("all_new"), not null
-# chat_quick_reaction_type :integer default("frequent"), not null
-# chat_quick_reactions_custom :string
-# chat_send_shortcut :integer default("enter"), not null
-# chat_separate_sidebar_mode :integer default("default"), not null
-# chat_sound :string
-# composition_mode :integer default(1), not null
-# default_calendar :integer default("none_selected"), not null
-# digest_after_minutes :integer
-# discourse_rewind_dismissed_at :datetime
-# discourse_rewind_enabled :boolean default(TRUE), not null
-# discourse_rewind_share_publicly :boolean default(FALSE), not null
-# dismissed_channel_retention_reminder :boolean
-# dismissed_dm_retention_reminder :boolean
-# dynamic_favicon :boolean default(FALSE), not null
-# email_digests :boolean
-# email_in_reply_to :boolean default(TRUE), not null
-# email_level :integer default(1), not null
-# email_messages_level :integer default(0), not null
-# email_previous_replies :integer default(2), not null
-# enable_allowed_pm_users :boolean default(FALSE), not null
-# enable_defer :boolean default(FALSE), not null
-# enable_markdown_monospace_font :boolean default(TRUE), not null
-# enable_quoting :boolean default(TRUE), not null
-# enable_smart_lists :boolean default(TRUE), not null
-# external_links_in_new_tab :boolean default(FALSE), not null
-# hide_presence :boolean default(FALSE), not null
-# hide_profile :boolean default(FALSE), not null
-# hide_profile_and_presence :boolean default(FALSE), not null
-# ignore_channel_wide_mention :boolean
-# include_tl0_in_digests :boolean default(FALSE)
-# interface_color_mode :integer default(1), not null
-# last_redirected_to_top_at :datetime
-# like_notification_frequency :integer default(1), not null
-# mailing_list_mode :boolean default(FALSE), not null
-# mailing_list_mode_frequency :integer default(1), not null
-# new_topic_duration_minutes :integer
-# notification_level_when_assigned :integer default("watch_topic"), not null
-# notification_level_when_replying :integer
-# notify_on_linked_posts :boolean default(TRUE), not null
-# notify_on_solved :boolean default(TRUE), not null
-# oldest_search_log_date :datetime
-# only_chat_push_notifications :boolean
-# policy_email_frequency :integer default("never"), not null
-# seen_popups :integer is an Array
-# show_original_content :boolean default(FALSE), not null
-# show_thread_title_prompts :boolean default(TRUE), not null
-# sidebar_link_to_filtered_list :boolean default(FALSE), not null
-# sidebar_show_count_of_new_items :boolean default(FALSE), not null
-# skip_new_user_tips :boolean default(FALSE), not null
-# text_size_key :integer default(0), not null
-# text_size_seq :integer default(0), not null
-# theme_ids :integer default([]), not null, is an Array
-# theme_key_seq :integer default(0), not null
-# timezone :string
-# title_count_mode_key :integer default(0), not null
-# topics_unread_when_closed :boolean default(TRUE), not null
-# watched_precedence_over_muted :boolean default(FALSE), not null
-# color_scheme_id :integer
-# dark_scheme_id :integer
-# homepage_id :integer
-# user_id :integer not null, primary key
+# ai_search_discoveries :boolean default(TRUE), not null
+# allow_private_messages :boolean default(TRUE), not null
+# auto_image_caption :boolean default(FALSE), not null
+# auto_track_topics_after_msecs :integer
+# automatically_unpin_topics :boolean default(TRUE), not null
+# bookmark_auto_delete_preference :integer default(3), not null
+# chat_email_frequency :integer default("when_away"), not null
+# chat_enabled :boolean default(TRUE), not null
+# chat_header_indicator_preference :integer default("all_new"), not null
+# chat_quick_reaction_type :integer default("frequent"), not null
+# chat_quick_reactions_custom :string
+# chat_send_shortcut :integer default("enter"), not null
+# chat_separate_sidebar_mode :integer default("default"), not null
+# chat_sound :string
+# composition_mode :integer default(1), not null
+# default_calendar :integer default("none_selected"), not null
+# digest_after_minutes :integer
+# discourse_rewind_dismissed_at :datetime
+# discourse_rewind_enabled :boolean default(TRUE), not null
+# discourse_rewind_share_publicly :boolean default(FALSE), not null
+# dismissed_channel_retention_reminder :boolean
+# dismissed_dm_retention_reminder :boolean
+# dynamic_favicon :boolean default(FALSE), not null
+# email_digests :boolean
+# email_in_reply_to :boolean default(TRUE), not null
+# email_level :integer default(1), not null
+# email_messages_level :integer default(0), not null
+# email_previous_replies :integer default(2), not null
+# enable_allowed_pm_users :boolean default(FALSE), not null
+# enable_defer :boolean default(FALSE), not null
+# enable_markdown_monospace_font :boolean default(TRUE), not null
+# enable_quoting :boolean default(TRUE), not null
+# enable_smart_lists :boolean default(TRUE), not null
+# enable_upcoming_change_available_notifications :boolean default(TRUE), not null
+# external_links_in_new_tab :boolean default(FALSE), not null
+# hide_presence :boolean default(FALSE), not null
+# hide_profile :boolean default(FALSE), not null
+# hide_profile_and_presence :boolean default(FALSE), not null
+# ignore_channel_wide_mention :boolean
+# include_tl0_in_digests :boolean default(FALSE)
+# interface_color_mode :integer default(1), not null
+# last_redirected_to_top_at :datetime
+# like_notification_frequency :integer default(1), not null
+# mailing_list_mode :boolean default(FALSE), not null
+# mailing_list_mode_frequency :integer default(1), not null
+# new_topic_duration_minutes :integer
+# notification_level_when_assigned :integer default("watch_topic"), not null
+# notification_level_when_replying :integer
+# notify_on_linked_posts :boolean default(TRUE), not null
+# notify_on_solved :boolean default(TRUE), not null
+# oldest_search_log_date :datetime
+# only_chat_push_notifications :boolean
+# policy_email_frequency :integer default("never"), not null
+# seen_popups :integer is an Array
+# show_original_content :boolean default(FALSE), not null
+# show_thread_title_prompts :boolean default(TRUE), not null
+# sidebar_link_to_filtered_list :boolean default(FALSE), not null
+# sidebar_show_count_of_new_items :boolean default(FALSE), not null
+# skip_new_user_tips :boolean default(FALSE), not null
+# text_size_key :integer default(0), not null
+# text_size_seq :integer default(0), not null
+# theme_ids :integer default([]), not null, is an Array
+# theme_key_seq :integer default(0), not null
+# timezone :string
+# title_count_mode_key :integer default(0), not null
+# topics_unread_when_closed :boolean default(TRUE), not null
+# watched_precedence_over_muted :boolean default(FALSE), not null
+# color_scheme_id :integer
+# dark_scheme_id :integer
+# homepage_id :integer
+# user_id :integer not null, primary key
#
# Indexes
#
diff --git a/app/serializers/user_option_serializer.rb b/app/serializers/user_option_serializer.rb
index 18e5fefbcbd..9b2c4879270 100644
--- a/app/serializers/user_option_serializer.rb
+++ b/app/serializers/user_option_serializer.rb
@@ -24,6 +24,7 @@ class UserOptionSerializer < ApplicationSerializer
:email_in_reply_to,
:like_notification_frequency,
:notify_on_linked_posts,
+ :enable_upcoming_change_available_notifications,
:include_tl0_in_digests,
:theme_ids,
:theme_key_seq,
diff --git a/app/services/upcoming_changes/action/notify_admins_of_available_change.rb b/app/services/upcoming_changes/action/notify_admins_of_available_change.rb
index 160e88fcc97..596d87e6e0c 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
@@ -16,7 +16,9 @@ class UpcomingChanges::Action::NotifyAdminsOfAvailableChange < Service::ActionBa
option :all_admins
def call
- notify_admins
+ eligible_admins = find_eligible_admins
+ return if eligible_admins.empty?
+ notify_admins(eligible_admins:)
create_event
log_action
true
@@ -24,11 +26,21 @@ class UpcomingChanges::Action::NotifyAdminsOfAvailableChange < Service::ActionBa
private
- def notify_admins
+ def find_eligible_admins
+ eligible_admin_ids =
+ UserOption
+ .where(user_id: all_admins.map(&:id))
+ .where(enable_upcoming_change_available_notifications: true)
+ .pluck(:user_id)
+ .to_set
+ all_admins.select { |admin| eligible_admin_ids.include?(admin.id) }
+ end
+
+ def notify_admins(eligible_admins:)
existing_notifications =
Notification.where(
notification_type: Notification.types[:upcoming_change_available],
- user_id: all_admins.map(&:id),
+ user_id: eligible_admins.map(&:id),
read: false,
)
existing_notification_rows = existing_notifications.to_a
@@ -36,7 +48,7 @@ class UpcomingChanges::Action::NotifyAdminsOfAvailableChange < Service::ActionBa
merge_with_existing = existing_notification_rows.present?
bulk_notification_new_records =
- all_admins.map do |admin|
+ eligible_admins.map do |admin|
{
user_id: admin.id,
notification_type: Notification.types[:upcoming_change_available],
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb
index f1cc14e1f98..2d752c53b56 100644
--- a/app/services/user_updater.rb
+++ b/app/services/user_updater.rb
@@ -40,6 +40,7 @@ class UserUpdater
email_in_reply_to
like_notification_frequency
notify_on_linked_posts
+ enable_upcoming_change_available_notifications
include_tl0_in_digests
theme_ids
allow_private_messages
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 42b05e5da54..e4ba5dd6738 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1617,6 +1617,7 @@ en:
in_specific_groups: "The user is in the specific groups required for this change"
enabled_for_everyone: "This change is enabled for all members"
enabled_for_no_one: "This change is disabled for all members"
+ enable_available_notifications: "Notify me when an upcoming change becomes available for preview"
user_notifications:
filters:
@@ -1640,7 +1641,7 @@ en:
normal_option: "Normal"
normal_option_title: "You will be notified if this user replies to you, quotes you, or mentions you."
notification_schedule:
- title: "Notification Schedule"
+ title: "Notification schedule"
label: "Enable custom notification schedule"
tip: "Outside of these hours your notifications will be paused."
midnight: "Midnight"
@@ -1684,13 +1685,13 @@ en:
notifications: "Notifications"
statistics: "Stats"
desktop_notifications:
- label: "Live Notifications"
+ label: "Live notifications"
not_supported: "Notifications are not supported on this browser. Sorry."
- perm_default: "Turn On Notifications"
- perm_denied_btn: "Permission Denied"
+ perm_default: "Turn on notifications"
+ perm_denied_btn: "Permission denied"
perm_denied_expl: "You denied permission for notifications. Allow notifications via your browser settings."
- disable: "Disable Notifications"
- enable: "Enable Notifications"
+ disable: "Disable notifications"
+ enable: "Enable notifications"
each_browser_note: "Note: You have to change this setting on every browser you use. All notifications will be disabled if you pause notifications from user menu, regardless of this setting."
consent_prompt: "Do you want live notifications when people reply to your posts?"
dismiss: "Dismiss"
diff --git a/db/migrate/20260514043815_add_enable_upcoming_change_available_notifications_to_user_options.rb b/db/migrate/20260514043815_add_enable_upcoming_change_available_notifications_to_user_options.rb
new file mode 100644
index 00000000000..638692292e3
--- /dev/null
+++ b/db/migrate/20260514043815_add_enable_upcoming_change_available_notifications_to_user_options.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class AddEnableUpcomingChangeAvailableNotificationsToUserOptions < ActiveRecord::Migration[8.0]
+ def change
+ add_column :user_options,
+ :enable_upcoming_change_available_notifications,
+ :boolean,
+ default: true,
+ null: false
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 61117b471d5..d9fd35b7c79 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -10592,7 +10592,8 @@ CREATE TABLE public.user_options (
discourse_rewind_dismissed_at timestamp(6) without time zone,
discourse_rewind_enabled boolean DEFAULT true NOT NULL,
notify_on_solved boolean DEFAULT true NOT NULL,
- show_original_content boolean DEFAULT false NOT NULL
+ show_original_content boolean DEFAULT false NOT NULL,
+ enable_upcoming_change_available_notifications boolean DEFAULT true NOT NULL
);
@@ -20802,6 +20803,7 @@ ALTER TABLE ONLY public.ad_plugin_house_ads_groups
SET search_path TO "$user", public;
INSERT INTO "schema_migrations" (version) VALUES
+('20260514043815'),
('20260513105516'),
('20260513101242'),
('20260513055222'),
diff --git a/frontend/discourse/app/controllers/preferences/notifications.js b/frontend/discourse/app/controllers/preferences/notifications.js
index 78eef28eb11..358532afd31 100644
--- a/frontend/discourse/app/controllers/preferences/notifications.js
+++ b/frontend/discourse/app/controllers/preferences/notifications.js
@@ -29,6 +29,7 @@ export default class NotificationsController extends Controller {
"new_topic_duration_minutes",
"notification_level_when_replying",
"notify_on_linked_posts",
+ "enable_upcoming_change_available_notifications",
"user_notification_schedule",
],
{ page: "notifications" }
diff --git a/frontend/discourse/app/models/user.js b/frontend/discourse/app/models/user.js
index 91a15fa35d7..a45fd94d8c8 100644
--- a/frontend/discourse/app/models/user.js
+++ b/frontend/discourse/app/models/user.js
@@ -125,6 +125,7 @@ let userOptionFields = [
"enable_markdown_monospace_font",
"enable_quoting",
"enable_smart_lists",
+ "enable_upcoming_change_available_notifications",
"external_links_in_new_tab",
"hide_presence",
"hide_profile",
diff --git a/frontend/discourse/app/templates/preferences/notifications.gjs b/frontend/discourse/app/templates/preferences/notifications.gjs
index 186fbb0c0f8..14c72261e61 100644
--- a/frontend/discourse/app/templates/preferences/notifications.gjs
+++ b/frontend/discourse/app/templates/preferences/notifications.gjs
@@ -57,6 +57,21 @@ export default <template>
</div>
{{/unless}}
+ {{#if @controller.model.admin}}
+ <div class="control-group upcoming-changes">
+ <label class="control-label">{{i18n
+ "user.upcoming_changes.title"
+ }}</label>
+
+ <PreferenceCheckbox
+ @labelKey="user.upcoming_changes.enable_available_notifications"
+ @checked={{@controller.model.user_option.enable_upcoming_change_available_notifications}}
+ data-setting-name="user-enable-upcoming-change-available-notifications"
+ class="pref-enable-upcoming-change-available-notifications"
+ />
+ </div>
+ {{/if}}
+
<UserNotificationSchedule @model={{@controller.model}} />
<span>
diff --git a/frontend/discourse/tests/acceptance/user-preferences-notifications-test.js b/frontend/discourse/tests/acceptance/user-preferences-notifications-test.js
index 62e6f4dc124..d7f2af5a88b 100644
--- a/frontend/discourse/tests/acceptance/user-preferences-notifications-test.js
+++ b/frontend/discourse/tests/acceptance/user-preferences-notifications-test.js
@@ -150,3 +150,26 @@ acceptance("User Notifications - Users - Ignore User", function (needs) {
assert.deepEqual(options, expected, "options are correct");
});
});
+
+acceptance("User Notifications - Upcoming Changes - Admin", function (needs) {
+ needs.user({ admin: true });
+
+ test("Shows the upcoming changes preference", async function (assert) {
+ await visit("/u/eviltrout/preferences/notifications");
+
+ assert.dom(".control-group.upcoming-changes").exists();
+ });
+});
+
+acceptance(
+ "User Notifications - Upcoming Changes - Regular User",
+ function (needs) {
+ needs.user();
+
+ test("Does not show the upcoming changes preference", async function (assert) {
+ await visit("/u/charlie/preferences/notifications");
+
+ assert.dom(".control-group.upcoming-changes").doesNotExist();
+ });
+ }
+);
diff --git a/spec/requests/api/schemas/json/user_get_response.json b/spec/requests/api/schemas/json/user_get_response.json
index f2a2ad74375..eb0aaa4651c 100644
--- a/spec/requests/api/schemas/json/user_get_response.json
+++ b/spec/requests/api/schemas/json/user_get_response.json
@@ -753,6 +753,9 @@
"notify_on_linked_posts": {
"type": "boolean"
},
+ "enable_upcoming_change_available_notifications": {
+ "type": "boolean"
+ },
"include_tl0_in_digests": {
"type": "boolean"
},
@@ -859,6 +862,7 @@
"email_in_reply_to",
"like_notification_frequency",
"notify_on_linked_posts",
+ "enable_upcoming_change_available_notifications",
"include_tl0_in_digests",
"theme_ids",
"theme_key_seq",
diff --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.rb
index 31ee71c361d..8ebd2990a51 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
@@ -187,6 +187,67 @@ RSpec.describe UpcomingChanges::Action::NotifyAdminsOfAvailableChange do
end
end
+ context "when an admin has disabled upcoming change available notifications" do
+ before { admin_2.user_option.update!(enable_upcoming_change_available_notifications: false) }
+
+ it "only creates a notification for admins who have the preference enabled" do
+ expect { result }.to change {
+ Notification.where(
+ notification_type: Notification.types[:upcoming_change_available],
+ ).count
+ }.by(1)
+
+ expect(
+ Notification.exists?(
+ notification_type: Notification.types[:upcoming_change_available],
+ user_id: admin_1.id,
+ ),
+ ).to eq(true)
+ expect(
+ Notification.exists?(
+ notification_type: Notification.types[:upcoming_change_available],
+ user_id: admin_2.id,
+ ),
+ ).to eq(false)
+ end
+
+ context "when no admins have the preference enabled" do
+ before do
+ admin_1.user_option.update!(enable_upcoming_change_available_notifications: false)
+ end
+
+ it "does not create any notifications" do
+ expect { result }.not_to change {
+ Notification.where(
+ notification_type: Notification.types[:upcoming_change_available],
+ ).count
+ }
+ end
+
+ it "does not create an admins_notified_available_change event" do
+ expect { result }.not_to change {
+ UpcomingChangeEvent.where(
+ event_type: :admins_notified_available_change,
+ upcoming_change_name: :test_upcoming_change,
+ ).count
+ }
+ end
+
+ it "does not log a staff action" do
+ expect { result }.not_to change {
+ UserHistory.where(
+ action: UserHistory.actions[:upcoming_change_available],
+ subject: "test_upcoming_change",
+ ).count
+ }
+ end
+
+ it "returns nil" do
+ expect(result).to be_nil
+ end
+ end
+ end
+
context "when there is an existing notification with the old data format" do
before do
Fabricate(