Skip to content

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

FEATURE: Merge permanent upcoming changes with new features feed (#38526)

Martin Brennan1cb6d36fefa8
diff --git a/app/assets/stylesheets/admin/upcoming-changes.scss b/app/assets/stylesheets/admin/upcoming-changes.scss
index f200b74f893..7579618ed1a 100644
--- a/app/assets/stylesheets/admin/upcoming-changes.scss
+++ b/app/assets/stylesheets/admin/upcoming-changes.scss
@@ -67,10 +67,6 @@
height: 0.75em;
color: var(--primary-high);
}
-
- &.--status-permanent {
- background-color: var(--success-low);
- }
}
&__groups {
diff --git a/app/controllers/admin/config/upcoming_changes_controller.rb b/app/controllers/admin/config/upcoming_changes_controller.rb
index 9fb58946b8f..14afb92ef52 100644
--- a/app/controllers/admin/config/upcoming_changes_controller.rb
+++ b/app/controllers/admin/config/upcoming_changes_controller.rb
@@ -4,7 +4,9 @@ class Admin::Config::UpcomingChangesController < Admin::AdminController
def index
return if !request.xhr?
- UpcomingChanges::List.call(service_params) do
+ filter_statuses = params[:filter_statuses]&.split(",") || []
+
+ UpcomingChanges::List.call(service_params.merge(options: { filter_statuses: })) do
on_success { |upcoming_changes:| render(json: upcoming_changes) }
on_failed_policy(:current_user_is_admin) { raise Discourse::InvalidAccess }
end
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb
index bcabd7b9a46..742a518866a 100644
--- a/app/controllers/admin/dashboard_controller.rb
+++ b/app/controllers/admin/dashboard_controller.rb
@@ -44,13 +44,17 @@ class Admin::DashboardController < Admin::StaffController
end
new_features = DiscourseUpdates.new_features(force_refresh:)
+ new_features_with_permanent_uc =
+ DiscourseUpdates.merge_new_features_with_upcoming_changes(
+ new_features&.map { |item| item.symbolize_keys } || [],
+ )
- if current_user.admin? && most_recent = new_features&.first
- DiscourseUpdates.bump_last_viewed_feature_date(current_user.id, most_recent["created_at"])
+ if current_user.admin? && most_recent = new_features_with_permanent_uc&.first
+ DiscourseUpdates.bump_last_viewed_feature_date(current_user.id, most_recent[:created_at])
end
data = {
- new_features: new_features,
+ new_features: new_features_with_permanent_uc,
has_unseen_features: DiscourseUpdates.has_unseen_features?(current_user.id),
release_notes_link: AdminDashboardGeneralData.fetch_cached_stats["release_notes_link"],
}
diff --git a/app/jobs/scheduled/check_new_features.rb b/app/jobs/scheduled/check_new_features.rb
index b69410f3516..b249903ab79 100644
--- a/app/jobs/scheduled/check_new_features.rb
+++ b/app/jobs/scheduled/check_new_features.rb
@@ -7,40 +7,83 @@ module Jobs
def execute(args)
admin_ids = User.human_users.where(admin: true).pluck(:id)
- prev_most_recent = DiscourseUpdates.new_features&.first
+ # Before we download the latest list from Meta:
+ #
+ # - Some admins have no "last time I looked at new features" stored yet.
+ # - If we already have at least one new-feature item saved for this site,
+ # set that stored time for them to the newest thing we know about,
+ # including permanent upcoming changes (those might be newer than the
+ # saved Meta list).
+ # - If we have no saved Meta items yet, do not set that time here. Only an
+ # upcoming change might exist; setting the time from that alone would
+ # make us think they are already up to date and we would skip sending the
+ # new-features notification.
+ new_features_from_feed = DiscourseUpdates.new_features
+ new_features_with_permanent_uc = find_new_features
+ prev_most_recent =
+ if new_features_from_feed.present?
+ new_features_with_permanent_uc&.first&.symbolize_keys || nil
+ else
+ nil
+ end
if prev_most_recent
admin_ids.each do |admin_id|
if DiscourseUpdates.get_last_viewed_feature_date(admin_id).blank?
- DiscourseUpdates.bump_last_viewed_feature_date(admin_id, prev_most_recent["created_at"])
+ DiscourseUpdates.bump_last_viewed_feature_date(admin_id, prev_most_recent[:created_at])
end
end
end
- # this memoization may seem pointless, but it actually avoids us hitting
+ # This memoization may seem pointless, but it actually avoids us hitting
# Meta repeatedly and getting rate-limited when this job is ran on a
# multisite cluster.
- # in multisite, the `execute` method (of the same instance) is called for
+ #
+ # In multisite, the `execute` method (of the same instance) is called for
# every site in the cluster.
- @new_features_json ||= DiscourseUpdates.new_features_payload
+ @new_features_json ||= DiscourseUpdates.new_features_response_json
DiscourseUpdates.update_new_features(@new_features_json)
- new_most_recent = DiscourseUpdates.new_features&.first
+ # After the download is saved:
+ #
+ # - If an admin has no stored "last looked" time, or it is older than the
+ # newest item (Meta list plus permanent upcoming changes), send the
+ # new-features notification and update their stored time to that newest
+ # item. Compare using whole seconds so Redis round-trip (.to_s then parse)
+ # does not look older than in-memory DB timestamps within the same second.
+ new_features_with_permanent_uc = find_new_features
+ new_most_recent = new_features_with_permanent_uc&.first&.symbolize_keys
if new_most_recent
- most_recent_feature_date = Time.zone.parse(new_most_recent["created_at"])
+ most_recent_created_at = new_most_recent[:created_at]
+ most_recent_feature_date =
+ (
+ if most_recent_created_at.is_a?(String)
+ Time.zone.parse(most_recent_created_at)
+ else
+ most_recent_created_at
+ end
+ )
+
admin_ids.each do |admin_id|
admin_last_viewed_feature_date = DiscourseUpdates.get_last_viewed_feature_date(admin_id)
if admin_last_viewed_feature_date.blank? ||
- admin_last_viewed_feature_date < most_recent_feature_date
+ admin_last_viewed_feature_date.to_i < most_recent_feature_date.to_i
Notification.consolidate_or_create!(
user_id: admin_id,
notification_type: Notification.types[:new_features],
data: {
},
)
- DiscourseUpdates.bump_last_viewed_feature_date(admin_id, new_most_recent["created_at"])
+ DiscourseUpdates.bump_last_viewed_feature_date(admin_id, most_recent_created_at)
end
end
end
end
+
+ def find_new_features
+ new_features = DiscourseUpdates.new_features
+ DiscourseUpdates.merge_new_features_with_upcoming_changes(
+ new_features&.map { |item| item.symbolize_keys } || [],
+ )
+ end
end
end
diff --git a/app/services/upcoming_changes/action/track_status_changes.rb b/app/services/upcoming_changes/action/track_status_changes.rb
index c4ce84b7d3a..030ce801609 100644
--- a/app/services/upcoming_changes/action/track_status_changes.rb
+++ b/app/services/upcoming_changes/action/track_status_changes.rb
@@ -82,6 +82,8 @@ class UpcomingChanges::Action::TrackStatusChanges < Service::ActionBase
end
end
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+
{ status_changes:, notified_changes: }
end
diff --git a/app/services/upcoming_changes/list.rb b/app/services/upcoming_changes/list.rb
index b342a2af26e..d7cae3a5dee 100644
--- a/app/services/upcoming_changes/list.rb
+++ b/app/services/upcoming_changes/list.rb
@@ -3,6 +3,8 @@
class UpcomingChanges::List
include Service::Base
+ options { attribute :filter_statuses, :array, default: [] }
+
policy :current_user_is_admin
model :upcoming_changes, optional: true
step :load_upcoming_change_groups
@@ -15,13 +17,23 @@ class UpcomingChanges::List
guardian.is_admin?
end
- def fetch_upcoming_changes
+ def fetch_upcoming_changes(options:)
SiteSetting
.all_settings(
only_upcoming_changes: true,
include_hidden: true,
include_locale_setting: false,
)
+ .select do |setting|
+ if options.filter_statuses.any?
+ options
+ .filter_statuses
+ .map(&:to_sym)
+ .include?(UpcomingChanges.change_status(setting[:setting]))
+ else
+ true
+ end
+ end
.each do |setting|
setting[:value] = setting[:value] == "true"
diff --git a/config/initializers/015-track-upcoming-change-toggle.rb b/config/initializers/015-track-upcoming-change-toggle.rb
index 65798ecbe1f..a84eb5a3651 100644
--- a/config/initializers/015-track-upcoming-change-toggle.rb
+++ b/config/initializers/015-track-upcoming-change-toggle.rb
@@ -1,4 +1,7 @@
# frozen_string_literal: true
+
+Rails.application.config.after_initialize { UpcomingChanges.clear_caches! }
+
#
# Similar to 014-track-setting-changes.rb, we can react to upcoming changes
# being enabled/or disabled here for more complicated scenarios, where
diff --git a/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs b/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
index 752a05ef672..7fcddf431aa 100644
--- a/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
+++ b/frontend/discourse/admin/components/admin-config-areas/upcoming-change-item.gjs
@@ -94,10 +94,7 @@ export default class UpcomingChangeItem extends Component {
}
get enabledForDisabled() {
- return (
- this.args.change.upcoming_change.status === "permanent" ||
- this.savingEnabledFor
- );
+ return this.savingEnabledFor;
}
get showDependentSettingsLink() {
@@ -326,13 +323,6 @@ export default class UpcomingChangeItem extends Component {
</div>
{{/if}}
- {{#if (eq @change.upcoming_change.status "permanent")}}
- <div class="upcoming-change__status-notice">
- {{icon "triangle-exclamation"}}
- {{i18n "admin.upcoming_changes.permanent_notice"}}
- </div>
- {{/if}}
-
{{#if (eq @change.upcoming_change.status "stable")}}
<div class="upcoming-change__status-notice">
{{icon "triangle-exclamation"}}
@@ -353,13 +343,7 @@ export default class UpcomingChangeItem extends Component {
(concat "--status-" @change.upcoming_change.status)
}}
>
- {{icon
- (if
- (eq @change.upcoming_change.status "permanent")
- "lock"
- "far-circle-dot"
- )
- }}
+ {{icon "far-circle-dot"}}
{{i18n
(concat
"admin.upcoming_changes.statuses."
@@ -423,16 +407,12 @@ export default class UpcomingChangeItem extends Component {
{{#if (eq this.bufferedEnabledFor "groups")}}
<div class="upcoming-change__group-selection-wrapper">
- {{#if (eq @change.upcoming_change.status "permanent")}}
- {{i18n "admin.upcoming_changes.permanent_no_group_selection"}}
- {{else}}
- <GroupSelector
- @groupFinder={{this.groupFinder}}
- @groupNames={{this.bufferedGroups}}
- @onChange={{this.groupsChanged}}
- @placeholderKey="admin.upcoming_changes.select_groups"
- />
- {{/if}}
+ <GroupSelector
+ @groupFinder={{this.groupFinder}}
+ @groupNames={{this.bufferedGroups}}
+ @onChange={{this.groupsChanged}}
+ @placeholderKey="admin.upcoming_changes.select_groups"
+ />
{{#if this.bufferedGroupsDirty}}
<DButton
diff --git a/frontend/discourse/admin/routes/admin-config/upcoming-changes.js b/frontend/discourse/admin/routes/admin-config/upcoming-changes.js
index b7b7a675e23..e3e2055cf73 100644
--- a/frontend/discourse/admin/routes/admin-config/upcoming-changes.js
+++ b/frontend/discourse/admin/routes/admin-config/upcoming-changes.js
@@ -15,9 +15,9 @@ export default class AdminConfigUpcomingChangesRoute extends DiscourseRoute {
}
model() {
- return ajax("/admin/config/upcoming-changes").then(
- (result) => result.upcoming_changes
- );
+ return ajax(
+ "/admin/config/upcoming-changes?filter_statuses=experimental,alpha,beta,stable"
+ ).then((result) => result.upcoming_changes);
}
activate() {
diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb
index d25569658bd..e7de700743d 100644
--- a/lib/discourse_updates.rb
+++ b/lib/discourse_updates.rb
@@ -131,17 +131,6 @@ module DiscourseUpdates
last_installed_version || Discourse::VERSION::STRING
end
- def new_features_payload
- response =
- Excon.new(new_features_endpoint).request(expects: [200], method: :Get, read_timeout: 5)
- response.body
- end
-
- def update_new_features(payload = nil)
- payload ||= new_features_payload
- Discourse.redis.set(new_features_key, payload)
- end
-
def new_features(force_refresh: false)
update_new_features if force_refresh
@@ -151,7 +140,7 @@ module DiscourseUpdates
rescue StandardError
nil
end
- return nil if entries.nil?
+ return [] if entries.blank?
entries.select! do |item|
begin
@@ -165,21 +154,100 @@ module DiscourseUpdates
valid_version && valid_plugin_name
rescue StandardError
- nil
+ false
end
end
entries.sort_by { |item| Time.zone.parse(item["created_at"]).to_i }.reverse
end
+ def update_new_features(response_json = nil)
+ response_json ||= new_features_response_json
+ Discourse.redis.set(new_features_key, response_json)
+ end
+
+ def new_features_response_json
+ response =
+ Excon.new(new_features_endpoint).request(expects: [200], method: :Get, read_timeout: 5)
+ response.body
+ end
+
+ def merge_new_features_with_upcoming_changes(new_features)
+ # Any new features that have an upcoming_change_setting_name that is not
+ # in the permanent upcoming changes list are excluded, since sites can
+ # have different versions of Discourse deployed and may not have the
+ # upcoming change or the same status.
+ permanent_upcoming_change_names =
+ UpcomingChanges.permanent_upcoming_changes.map { |uc| uc[:setting].to_s }
+ new_features.reject! do |feature|
+ if feature[:upcoming_change_setting_name].present?
+ !permanent_upcoming_change_names.include?(feature[:upcoming_change_setting_name])
+ else
+ false
+ end
+ end
+
+ return new_features if permanent_upcoming_change_names.blank?
+
+ # Any permanent upcoming changes that have not been overridden/attached
+ # in the new features feed have to be injected into the array.
+ upcoming_changes_to_inject =
+ UpcomingChanges.permanent_upcoming_changes.reject do |permanent_uc|
+ new_features.any? do |feature|
+ feature[:upcoming_change_setting_name] == permanent_uc[:setting].to_s
+ end
+ end
+
+ upcoming_changes_to_inject.each do |permanent_uc|
+ # We track whenever an upcoming change moves from one status to another,
+ # the most logical datetime to use for created/released at in the UI is
+ # the datetime that the upcoming change became permanent on this site.
+ became_permanent_at =
+ UpcomingChanges.current_statuses.dig(permanent_uc[:setting].to_s, :changed_at) ||
+ Time.zone.now
+
+ new_features << {
+ title: permanent_uc[:humanized_name],
+ description: permanent_uc[:description],
+ link: permanent_uc[:upcoming_change][:learn_more_url],
+ created_at: became_permanent_at,
+ updated_at: became_permanent_at,
+ released_at: became_permanent_at,
+ screenshot_url: permanent_uc.dig(:upcoming_change, :image, :url),
+ upcoming_change_setting_name: permanent_uc[:setting],
+ }
+ end
+
+ new_features
+ .sort_by do |item|
+ if item[:created_at].is_a?(String)
+ Time.zone.parse(item[:created_at]).to_i
+ else
+ item[:created_at].to_i
+ end
+ end
+ .reverse
+ end
+
def has_unseen_features?(user_id)
- entries = new_features
+ entries =
+ merge_new_features_with_upcoming_changes(
+ new_features&.map { |item| item.symbolize_keys } || [],
+ )
return false if entries.nil?
last_seen = new_features_last_seen(user_id)
if last_seen.present?
- entries.select! { |item| Time.zone.parse(item["created_at"]) > last_seen }
+ entries.select! do |item|
+ created_at =
+ if item[:created_at].is_a?(String)
+ Time.zone.parse(item[:created_at])
+ else
+ item[:created_at]
+ end
+ created_at.to_i > last_seen.to_i
+ end
end
entries.size > 0
@@ -193,14 +261,20 @@ module DiscourseUpdates
def mark_new_features_as_seen(user_id)
entries =
- begin
- JSON.parse(Discourse.redis.get(new_features_key))
- rescue StandardError
- nil
+ merge_new_features_with_upcoming_changes(
+ new_features&.map { |item| item.symbolize_keys } || [],
+ )
+ return nil if entries.blank?
+
+ last_seen =
+ entries.max_by do |item|
+ val = item.with_indifferent_access[:created_at]
+ val.is_a?(String) ? Time.zone.parse(val).to_i : val.to_i
end
- return nil if entries.nil?
- last_seen = entries.max_by { |x| x["created_at"] }
- Discourse.redis.set(new_features_last_seen_key(user_id), last_seen["created_at"])
+ Discourse.redis.set(
+ new_features_last_seen_key(user_id),
+ last_seen.with_indifferent_access[:created_at],
+ )
end
def get_last_viewed_feature_date(user_id)
diff --git a/lib/upcoming_changes.rb b/lib/upcoming_changes.rb
index f2162184e5a..4c52c9061ee 100644
--- a/lib/upcoming_changes.rb
+++ b/lib/upcoming_changes.rb
@@ -47,15 +47,21 @@ module UpcomingChanges
end
end
- def self.image_data(change_setting_name)
+ def self.image_data(change_setting_name, include_file_path: false)
width, height = nil, nil
- File.open(File.join(Rails.public_path, image_path(change_setting_name)), "rb") do |file|
+ full_file_path = File.join(Rails.public_path, image_path(change_setting_name))
+
+ File.open(full_file_path, "rb") do |file|
image_info = FastImage.new(file)
width, height = image_info.size
end
- { url: "#{Discourse.base_url}/#{image_path(change_setting_name)}", width:, height: }
+ data = { url: "#{Discourse.base_url}/#{image_path(change_setting_name)}", width:, height: }
+
+ data[:file_path] = full_file_path if include_file_path
+
+ data
end
def self.change_metadata(change_setting_name)
@@ -265,4 +271,66 @@ module UpcomingChanges
{ enabled_for:, setting_groups: }
end
+
+ def self.clear_caches!
+ Discourse.cache.delete(current_statuses_cache_key)
+ Discourse.cache.delete(permanent_upcoming_changes_cache_key)
+ end
+
+ def self.current_statuses_cache_key
+ "upcoming_changes_current_statuses::#{Discourse.git_version}"
+ end
+
+ # This also only changes once per deploy, so we can cache to the git version
+ # to save time in other places in the codebase when we have to figure out
+ # when an upcoming change moved to its current status.
+ #
+ # This cache is automatically cleared when UpcomingChanges::Action::TrackStatusChanges
+ # is called, since that adds new UpcomingChangeEvent records.
+ def self.current_statuses
+ Discourse
+ .cache
+ .fetch(current_statuses_cache_key) do
+ results = DB.query(<<-SQL, status_changed: UpcomingChangeEvent.event_types[:status_changed])
+ WITH latest_status_changes AS (
+ SELECT upcoming_change_name, MAX(created_at) as created_at
+ FROM upcoming_change_events
+ WHERE event_type = :status_changed
+ GROUP BY upcoming_change_name
+ ORDER BY MAX(created_at) DESC
+ )
+ SELECT latest_status_changes.upcoming_change_name, latest_status_changes.created_at, upcoming_change_events.event_data->>'new_value' as new_value
+ FROM latest_status_changes
+ INNER JOIN upcoming_change_events ON upcoming_change_events.upcoming_change_name = latest_status_changes.upcoming_change_name AND upcoming_change_events.created_at = latest_status_changes.created_at
+ ORDER BY latest_status_changes.created_at DESC
+ SQL
+
+ results.each_with_object({}) do |result, statuses|
+ statuses[result.upcoming_change_name] = {
+ status: result.new_value,
+ changed_at: result.created_at,
+ }
+ end
+ end
+ end
+
+ def self.permanent_upcoming_changes_cache_key
+ "upcoming_changes_permanent::#{Discourse.git_version}"
+ end
+
+ # These don't change except on deploy, so we can cache to the git version
+ # to save time in other places in the codebase when we have to figure out
+ # whether a change is permanent or not.
+ def self.permanent_upcoming_changes
+ Discourse
+ .cache
+ .fetch(permanent_upcoming_changes_cache_key) do
+ UpcomingChanges::List.call(
+ guardian: Discourse.system_user.guardian,
+ options: {
+ filter_statuses: [:permanent],
+ },
+ )&.upcoming_changes
+ end
+ end
end
diff --git a/spec/jobs/check_new_features_spec.rb b/spec/jobs/check_new_features_spec.rb
index fd6bb7048ff..aec7b373873 100644
--- a/spec/jobs/check_new_features_spec.rb
+++ b/spec/jobs/check_new_features_spec.rb
@@ -82,6 +82,198 @@ RSpec.describe Jobs::CheckNewFeatures do
).to eq(1)
end
+ context "when a permanent upcoming change is merged into an empty new-features feed" do
+ before do
+ UpcomingChanges.stubs(:image_exists?).returns(true)
+ UpcomingChanges.stubs(:image_data).returns(
+ {
+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ width: 244,
+ height: 66,
+ file_path: file_from_fixtures("logo.png", "images").path,
+ },
+ )
+ stub_new_features_endpoint(feature1)
+ end
+
+ after { clear_mocked_upcoming_change_metadata }
+
+ it "notifies admins and bumps last_viewed_feature_date from the status_changed time" do
+ Notification.destroy_all
+
+ status_changed_at = 1.day.ago
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+ event =
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ created_at: status_changed_at,
+ )
+
+ described_class.new.execute({})
+
+ expect(
+ admin1
+ .notifications
+ .where(notification_type: Notification.types[:new_features], read: false)
+ .count,
+ ).to eq(1)
+ expect(
+ admin2
+ .notifications
+ .where(notification_type: Notification.types[:new_features], read: false)
+ .count,
+ ).to eq(1)
+
+ status_changed_at_db = event.reload.created_at
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin1.id)).to be_within_one_second_of(
+ status_changed_at_db,
+ )
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin2.id)).to be_within_one_second_of(
+ status_changed_at_db,
+ )
+ end
+ end
+
+ context "when persisted feed is older than a permanent upcoming change" do
+ let(:feature_stale) do
+ build_feature_hash(id: 99, created_at: 3.days.ago, discourse_version: "2.8.1.beta12")
+ end
+
+ let(:feature_newer_than_uc) do
+ build_feature_hash(id: 100, created_at: 1.day.ago, discourse_version: "2.8.1.beta13")
+ end
+
+ before do
+ UpcomingChanges.stubs(:image_exists?).returns(true)
+ UpcomingChanges.stubs(:image_data).returns(
+ {
+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ width: 244,
+ height: 66,
+ file_path: file_from_fixtures("logo.png", "images").path,
+ },
+ )
+ stub_new_features_endpoint(feature_stale)
+ end
+
+ after { clear_mocked_upcoming_change_metadata }
+
+ it "seeds last_viewed to the UC when the fetch adds nothing newer, without notifying" do
+ Notification.destroy_all
+
+ uc_became_permanent_at = 2.days.ago
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ created_at: uc_became_permanent_at,
+ )
+
+ DiscourseUpdates.update_new_features([feature_stale].to_json)
+
+ described_class.new.execute({})
+
+ expect(
+ admin1.notifications.where(
+ notification_type: Notification.types[:new_features],
+ read: false,
+ ),
+ ).to be_empty
+ expect(
+ admin2.notifications.where(
+ notification_type: Notification.types[:new_features],
+ read: false,
+ ),
+ ).to be_empty
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin1.id)).to be_within_one_second_of(
+ uc_became_permanent_at,
+ )
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin2.id)).to be_within_one_second_of(
+ uc_became_permanent_at,
+ )
+ end
+
+ it "notifies and bumps last_viewed to a new feed item newer than the UC" do
+ Notification.destroy_all
+
+ uc_became_permanent_at = 2.days.ago
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ created_at: uc_became_permanent_at,
+ )
+
+ DiscourseUpdates.update_new_features([feature_stale].to_json)
+ stub_new_features_endpoint(feature_newer_than_uc, feature_stale)
+
+ described_class.new.execute({})
+
+ expect(
+ admin1
+ .notifications
+ .where(notification_type: Notification.types[:new_features], read: false)
+ .count,
+ ).to eq(1)
+ expect(
+ admin2
+ .notifications
+ .where(notification_type: Notification.types[:new_features], read: false)
+ .count,
+ ).to eq(1)
+ newer_time = Time.zone.parse(feature_newer_than_uc[:created_at])
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin1.id)).to be_within_one_second_of(
+ newer_time,
+ )
+ expect(DiscourseUpdates.get_last_viewed_feature_date(admin2.id)).to be_within_one_second_of(
+ newer_time,
+ )
+ end
+ end
+
it "consolidates new features notifications" do
Notification.destroy_all
diff --git a/spec/lib/discourse_updates_spec.rb b/spec/lib/discourse_updates_spec.rb
index 78e0e76590d..cc846c5bef1 100644
--- a/spec/lib/discourse_updates_spec.rb
+++ b/spec/lib/discourse_updates_spec.rb
@@ -204,6 +204,28 @@ RSpec.describe DiscourseUpdates do
expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(true)
end
+ it "filters out entries that raise while validating feed metadata" do
+ malformed_features = [
+ { "emoji" => "🤾", "title" => "Bells", "created_at" => 2.days.ago },
+ {
+ "emoji" => "🙈",
+ "title" => "Broken plugin row",
+ "created_at" => 1.day.ago,
+ "discourse_version" => "blah",
+ },
+ ]
+
+ Discourse.redis.set("new_features", MultiJson.dump(malformed_features))
+ Discourse
+ .expects(:has_needed_version?)
+ .with(Discourse::VERSION::STRING, "blah")
+ .once
+ .raises(StandardError)
+
+ result = DiscourseUpdates.new_features
+ expect(result.map { |item| item["title"] }).to eq(["Bells"])
+ end
+
it "correctly shows features by Discourse version" do
features_with_versions = [
{ "emoji" => "🤾", "title" => "Bells", "created_at" => 2.days.ago },
@@ -312,6 +334,247 @@ RSpec.describe DiscourseUpdates do
result = DiscourseUpdates.new_features(force_refresh: true)
expect(result.length).to eq(3)
end
+
+ context "when the only unseen item is an injected permanent upcoming change" do
+ before do
+ Discourse.redis.del("new_features_last_seen_user_#{admin.id}")
+ Discourse.redis.set("new_features", MultiJson.dump([]))
+
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+
+ UpcomingChanges.stubs(:image_exists?).returns(true)
+ UpcomingChanges.stubs(:image_data).returns(
+ {
+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ width: 244,
+ height: 66,
+ },
+ )
+ end
+
+ after { clear_mocked_upcoming_change_metadata }
+
+ it "marks the injected item as seen" do
+ freeze_time
+ expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(true)
+ DiscourseUpdates.mark_new_features_as_seen(admin.id)
+ expect(DiscourseUpdates.has_unseen_features?(admin.id)).to eq(false)
+ end
+ end
+ end
+
+ describe ".merge_new_features_with_upcoming_changes" do
+ def mock_merge_uc_metadata(uc_status)
+ mock_upcoming_change_metadata(
+ {
+ floating_dismiss_topics_on_mobile: {
+ impact: "feature,all_members",
+ status: :beta,
+ impact_type: "feature",
+ impact_role: "all_members",
+ learn_more_url: "https://meta.discourse.org/t/-/387322",
+ },
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: uc_status,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+ end
+
+ def feature_for_uc_setting(features)
+ features.find { |f| f[:upcoming_change_setting_name].to_s == "enable_upload_debug_mode" }
+ end
+
+ before do
+ UpcomingChanges.stubs(:image_exists?).returns(true)
+ UpcomingChanges.stubs(:image_data).returns(
+ {
+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ width: 244,
+ height: 66,
+ file_path: file_from_fixtures("logo.png", "images").path,
+ },
+ )
+ end
+
+ after { clear_mocked_upcoming_change_metadata }
+
+ context "when there are no permanent upcoming changes" do
+ before { mock_merge_uc_metadata(:beta) }
+
+ it "returns the same new_features array without modification" do
+ features = [
+ {
+ title: "Feed item",
+ description: "From meta",
+ created_at: 1.hour.ago.to_s,
+ upcoming_change_setting_name: "other_setting",
+ },
+ ]
+
+ result = described_class.merge_new_features_with_upcoming_changes(features)
+ expect(result).to eq(features)
+ end
+ end
+
+ context "when the feed already includes a feature for an upcoming change" do
+ let(:upcoming_change_setting_name) { "enable_upload_debug_mode" }
+ let(:feed_feature) do
+ {
+ title: "Official feed title",
+ description: "Marketing copy from the new features feed",
+ link: "https://meta.discourse.org/t/feed-release-note",
+ screenshot_url: "https://meta.discourse.org/feed-screenshot.png",
+ created_at: 1.week.ago.to_s,
+ updated_at: 1.week.ago.to_s,
+ released_at: 1.week.ago.to_s,
+ upcoming_change_setting_name: upcoming_change_setting_name,
+ }
+ end
+
+ context "when the upcoming change is permanent" do
+ before { mock_merge_uc_metadata(:permanent) }
+
+ it "keeps the feed row and does not inject a duplicate from the UC" do
+ new_features = [feed_feature.deep_dup]
+ result = described_class.merge_new_features_with_upcoming_changes(new_features)
+
+ expect(result.length).to eq(1)
+ row = feature_for_uc_setting(result)
+ expect(row[:title]).to eq("Official feed title")
+ expect(row[:description]).to eq("Marketing copy from the new features feed")
+ expect(row[:link]).to eq("https://meta.discourse.org/t/feed-release-note")
+ expect(row[:screenshot_url]).to eq("https://meta.discourse.org/feed-screenshot.png")
+ expect(row[:upcoming_change_setting_name]).to eq("enable_upload_debug_mode")
+ end
+ end
+
+ context "when the upcoming change is not permanent" do
+ before { mock_merge_uc_metadata(:beta) }
+
+ it "excludes the item from the new features feed" do
+ new_features = [feed_feature.deep_dup]
+ result = described_class.merge_new_features_with_upcoming_changes(new_features)
+ expect(result.length).to eq(0)
+ end
+ end
+
+ context "when this site does not have any permanent upcoming changes" do
+ before { mock_merge_uc_metadata(:beta) }
+
+ it "excludes the feed item with the upcoming_change_setting_name" do
+ new_features = [feed_feature.deep_dup]
+ result = described_class.merge_new_features_with_upcoming_changes(new_features)
+ expect(result.length).to eq(0)
+ end
+ end
+ end
+
+ context "when a permanent UC is not in the feed" do
+ before { mock_merge_uc_metadata(:permanent) }
+
+ it "injects a feature using UC name, description, learn URL, and screenshot" do
+ result = described_class.merge_new_features_with_upcoming_changes([])
+
+ expect(result.length).to eq(1)
+ feature = feature_for_uc_setting(result)
+ expect(feature[:title]).to eq(SiteSetting.humanized_names(:enable_upload_debug_mode))
+ expect(feature[:description]).to eq(SiteSetting.description(:enable_upload_debug_mode))
+ expect(feature[:link]).to eq("https://meta.discourse.org/t/-/1234")
+ expect(feature[:screenshot_url]).to eq(
+ UpcomingChanges.image_data(:enable_upload_debug_mode)[:url],
+ )
+ expect(feature[:upcoming_change_setting_name]).to eq(:enable_upload_debug_mode)
+ end
+
+ it "uses the status_changed event time when the UC became permanent" do
+ freeze_time
+ event_time = 3.days.ago
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ created_at: event_time,
+ )
+
+ result = described_class.merge_new_features_with_upcoming_changes([])
+ feature = feature_for_uc_setting(result)
+
+ expect(feature[:created_at]).to eq_time(event_time)
+ expect(feature[:updated_at]).to eq_time(event_time)
+ expect(feature[:released_at]).to eq_time(event_time)
+ end
+
+ it "uses the latest status_changed-to-permanent event when several exist" do
+ freeze_time
+ older = 5.days.ago
+ newer = 1.day.ago
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "beta",
+ "new_value" => "permanent",
+ },
+ created_at: older,
+ )
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ created_at: newer,
+ )
+
+ result = described_class.merge_new_features_with_upcoming_changes([])
+
+ expect(feature_for_uc_setting(result)[:created_at]).to eq_time(newer)
+ end
+
+ it "falls back to the current time when no matching event exists" do
+ freeze_time do
+ result = described_class.merge_new_features_with_upcoming_changes([])
+
+ expect(feature_for_uc_setting(result)[:created_at]).to eq_time(Time.zone.now)
+ end
+ end
+
+ it "ignores status_changed events that did not transition to permanent" do
+ freeze_time do
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "experimental",
+ "new_value" => "stable",
+ },
+ )
+
+ result = described_class.merge_new_features_with_upcoming_changes([])
+
+ expect(feature_for_uc_setting(result)[:created_at]).to eq_time(Time.zone.now)
+ end
+ end
+ end
end
describe "#get_last_viewed_feature_date" do
diff --git a/spec/lib/upcoming_changes_spec.rb b/spec/lib/upcoming_changes_spec.rb
index b49941242e2..dceefe61e3a 100644
--- a/spec/lib/upcoming_changes_spec.rb
+++ b/spec/lib/upcoming_changes_spec.rb
@@ -71,6 +71,23 @@ RSpec.describe UpcomingChanges do
expect(result[:width]).to eq(244)
expect(result[:height]).to eq(66)
end
+
+ context "when include_file_path is true" do
+ it "returns the image URL, width, height, and file path" do
+ result = described_class.image_data(setting_name, include_file_path: true)
+
+ expect(result[:file_path]).to eq(
+ File.join(
+ Rails.root,
+ "spec",
+ "fixtures",
+ "images",
+ "upcoming_changes",
+ "#{setting_name}.png",
+ ),
+ )
+ end
+ end
end
describe ".change_metadata" do
@@ -368,6 +385,110 @@ RSpec.describe UpcomingChanges do
end
end
+ describe ".current_statuses" do
+ include ActiveSupport::Testing::TimeHelpers
+
+ before { described_class.clear_caches! }
+
+ after do
+ described_class.clear_caches!
+ UpcomingChangeEvent.where(upcoming_change_name: "timeline_status_setting").delete_all
+ end
+
+ it "returns an empty hash when there are no status_changed events" do
+ expect(described_class.current_statuses).to eq({})
+ end
+
+ it "maps each upcoming change to the latest status_changed new_value and timestamp" do
+ travel_to Time.zone.parse("2024-06-01 12:00:00") do
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "timeline_status_setting",
+ event_data: {
+ "previous_value" => "alpha",
+ "new_value" => "beta",
+ },
+ )
+ end
+
+ latest_event =
+ travel_to(Time.zone.parse("2024-06-15 12:00:00")) do
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "timeline_status_setting",
+ event_data: {
+ "previous_value" => "beta",
+ "new_value" => "stable",
+ },
+ )
+ end
+
+ result = described_class.current_statuses
+
+ expect(result["timeline_status_setting"]).to eq(
+ { status: "stable", changed_at: latest_event.created_at },
+ )
+ end
+
+ it "caches the result so the SQL runs only once until the cache key is deleted" do
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "timeline_status_setting",
+ event_data: {
+ "previous_value" => nil,
+ "new_value" => "experimental",
+ },
+ )
+
+ allow(DB).to receive(:query).and_call_original
+
+ 2.times { described_class.current_statuses }
+ expect(DB).to have_received(:query).once
+
+ described_class.clear_caches!
+
+ described_class.current_statuses
+ expect(DB).to have_received(:query).twice
+ end
+ end
+
+ describe ".permanent_upcoming_changes" do
+ before do
+ described_class.clear_caches!
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ },
+ },
+ )
+ end
+
+ after { described_class.clear_caches! }
+
+ it "returns only changes whose metadata status is permanent" do
+ list = described_class.permanent_upcoming_changes
+
+ expect(list.all? { |c| described_class.change_status(c[:setting]) == :permanent }).to eq(true)
+ expect(list.map { |c| c[:setting] }).to include(:enable_upload_debug_mode)
+ end
+
+ it "caches the list so UpcomingChanges::List runs only once until the cache key is deleted" do
+ allow(UpcomingChanges::List).to receive(:call).and_call_original
+
+ 2.times { described_class.permanent_upcoming_changes }
+ expect(UpcomingChanges::List).to have_received(:call).once
+
+ described_class.clear_caches!
+
+ described_class.permanent_upcoming_changes
+ expect(UpcomingChanges::List).to have_received(:call).twice
+ end
+ end
+
describe ".enabled_for_user?" do
context "for logged-in user" do
fab!(:user)
diff --git a/spec/multisite/jobs_spec.rb b/spec/multisite/jobs_spec.rb
index b5afcd09402..c02e5a66aa1 100644
--- a/spec/multisite/jobs_spec.rb
+++ b/spec/multisite/jobs_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe "Running Sidekiq Jobs in Multisite", type: :multisite do
it "CheckNewFeatures should only hit the payload once" do
# otherwise it will get rate-limited by meta
- DiscourseUpdates.expects(:new_features_payload).returns([]).once
+ DiscourseUpdates.expects(:new_features_response_json).returns([]).once
Jobs::CheckNewFeatures.new.perform({})
end
end
diff --git a/spec/multisite/upcoming_changes_spec.rb b/spec/multisite/upcoming_changes_spec.rb
new file mode 100644
index 00000000000..a62fd053879
--- /dev/null
+++ b/spec/multisite/upcoming_changes_spec.rb
@@ -0,0 +1,99 @@
+# frozen_string_literal: true
+
+RSpec.describe "Multisite UpcomingChanges cache", type: :multisite do
+ before do
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ },
+ },
+ )
+ Rails.stubs(:public_path).returns(File.join(Rails.root, "spec", "fixtures"))
+ end
+
+ after do
+ %w[default second].each do |site|
+ RailsMultisite::ConnectionManagement.with_connection(site) do
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+ Discourse.cache.delete(UpcomingChanges.permanent_upcoming_changes_cache_key)
+ end
+ end
+ clear_mocked_upcoming_change_metadata
+ end
+
+ it "keeps current_statuses tied to each site's upcoming_change_events" do
+ test_multisite_connection("default") do
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+ UpcomingChangeEvent.where(upcoming_change_name: "enable_upload_debug_mode").delete_all
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "enable_upload_debug_mode",
+ event_data: {
+ "previous_value" => "stable",
+ "new_value" => "permanent",
+ },
+ )
+
+ expect(UpcomingChanges.current_statuses["enable_upload_debug_mode"][:status]).to eq(
+ "permanent",
+ )
+ end
+
+ test_multisite_connection("second") do
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+ UpcomingChangeEvent.where(upcoming_change_name: "enable_upload_debug_mode").delete_all
+
+ expect(UpcomingChanges.current_statuses).to eq({})
+ end
+ end
+
+ it "caches current_statuses on the default site" do
+ test_multisite_connection("default") do
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+ UpcomingChangeEvent.create!(
+ event_type: :status_changed,
+ upcoming_change_name: "multisite_cache_setting",
+ event_data: {
+ "previous_value" => nil,
+ "new_value" => "beta",
+ },
+ )
+
+ allow(DB).to receive(:query).and_call_original
+ 2.times { UpcomingChanges.current_statuses }
+ expect(DB).to have_received(:query).once
+ end
+ end
+
+ it "caches current_statuses on the second site" do
+ test_multisite_connection("second") do
+ Discourse.cache.delete(UpcomingChanges.current_statuses_cache_key)
+
+ allow(DB).to receive(:query).and_call_original
+ 2.times { UpcomingChanges.current_statuses }
+ expect(DB).to have_received(:query).once
+ end
+ end
+
+ it "caches permanent_upcoming_changes on the default site" do
+ test_multisite_connection("default") do
+ Discourse.cache.delete(UpcomingChanges.permanent_upcoming_changes_cache_key)
+ allow(UpcomingChanges::List).to receive(:call).and_call_original
+ 2.times { UpcomingChanges.permanent_upcoming_changes }
+ expect(UpcomingChanges::List).to have_received(:call).once
+ end
+ end
+
+ it "caches permanent_upcoming_changes on the second site" do
+ test_multisite_connection("second") do
+ Discourse.cache.delete(UpcomingChanges.permanent_upcoming_changes_cache_key)
+ allow(UpcomingChanges::List).to receive(:call).and_call_original
+ 2.times { UpcomingChanges.permanent_upcoming_changes }
+ expect(UpcomingChanges::List).to have_received(:call).once
+ end
+ end
+end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index db182964bf4..3e23d64738b 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -145,6 +145,7 @@ module TestSetup
NotificationEmailer.disable
SiteIconManager.disable
WordWatcher.disable_cache
+ UpcomingChanges.clear_caches!
SiteSetting.provider.all.each { |setting| SiteSetting.remove_override!(setting.name) }
diff --git a/spec/requests/admin/dashboard_controller_spec.rb b/spec/requests/admin/dashboard_controller_spec.rb
index 3e41daf09b0..312f7e044d0 100644
--- a/spec/requests/admin/dashboard_controller_spec.rb
+++ b/spec/requests/admin/dashboard_controller_spec.rb
@@ -166,7 +166,7 @@ RSpec.describe Admin::DashboardController do
get "/admin/whats-new.json"
expect(response.status).to eq(200)
json = response.parsed_body
- expect(json["new_features"]).to eq(nil)
+ expect(json["new_features"]).to eq([])
end
it "fails gracefully for invalid JSON" do
@@ -174,7 +174,7 @@ RSpec.describe Admin::DashboardController do
get "/admin/whats-new.json"
expect(response.status).to eq(200)
json = response.parsed_body
- expect(json["new_features"]).to eq(nil)
+ expect(json["new_features"]).to eq([])
end
it "includes new features when available" do
@@ -203,7 +203,7 @@ RSpec.describe Admin::DashboardController do
json = response.parsed_body
expect(json["new_features"].length).to eq(2)
- DiscourseUpdates.stubs(:new_features_payload).returns(
+ DiscourseUpdates.stubs(:new_features_response_json).returns(
[
{
"id" => "3",
@@ -278,6 +278,53 @@ RSpec.describe Admin::DashboardController do
get "/admin/whats-new.json"
expect(response.status).to eq(200)
end
+
+ context "when a permanent upcoming change exists and the feed is empty" do
+ before do
+ mock_upcoming_change_metadata(
+ {
+ enable_upload_debug_mode: {
+ impact: "other,developers",
+ status: :permanent,
+ impact_type: "other",
+ impact_role: "developers",
+ learn_more_url: "https://meta.discourse.org/t/-/1234",
+ },
+ },
+ )
+ UpcomingChanges.stubs(:image_exists?).returns(true)
+ UpcomingChanges.stubs(:image_data).returns(
+ {
+ url: "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ width: 244,
+ height: 66,
+ file_path: file_from_fixtures("logo.png", "images").path,
+ },
+ )
+ end
+
+ after { clear_mocked_upcoming_change_metadata }
+
+ it "includes the permanent upcoming change in the whats-new payload" do
+ freeze_time do
+ get "/admin/whats-new.json"
+ expect(response.status).to eq(200)
+ json = response.parsed_body
+ feature =
+ json["new_features"].find do |row|
+ row["upcoming_change_setting_name"] == "enable_upload_debug_mode"
+ end
+ expect(feature).to be_present
+ expect(feature["title"]).to eq(SiteSetting.humanized_names(:enable_upload_debug_mode))
+ expect(feature["description"]).to eq(SiteSetting.description(:enable_upload_debug_mode))
+ expect(feature["link"]).to eq("https://meta.discourse.org/t/-/1234")
+ expect(feature["screenshot_url"]).to eq(
+ "#{Discourse.base_url}/images/upcoming_changes/enable_upload_debug_mode.png",
+ )
+ expect(Time.parse(feature["created_at"])).to eq_time(Time.zone.now)
+ end
+ end
+ end
end
context "when logged in as a moderator" do
diff --git a/spec/services/upcoming_changes/list_spec.rb b/spec/services/upcoming_changes/list_spec.rb
index a91dd3ca215..59ddd2f461b 100644
--- a/spec/services/upcoming_changes/list_spec.rb
+++ b/spec/services/upcoming_changes/list_spec.rb
@@ -2,11 +2,12 @@
RSpec.describe UpcomingChanges::List do
describe ".call" do
- subject(:result) { described_class.call(params:, **dependencies) }
+ subject(:result) { described_class.call(params:, options:, **dependencies) }
fab!(:admin)
let(:dependencies) { { guardian: } }
let(:guardian) { admin.guardian }
+ let(:options) { {} }
let(:params) { {} }
before do
@@ -18,6 +19,12 @@ RSpec.describe UpcomingChanges::List do
impact_type: "other",
impact_role: "developers",
},
+ allow_user_locale: {
+ impact: "feature,all_members",
+ status: :beta,
+ impact_type: "feature",
+ impact_role: "all_members",
+ },
},
)
end
@@ -152,6 +159,18 @@ RSpec.describe UpcomingChanges::List do
)
end
end
+
+ context "when filtering by statuses" do
+ let(:options) { { filter_statuses: [:beta] } }
+
+ it "only includes upcoming changes with the given statuses" do
+ results = result.upcoming_changes
+ expect(
+ results.find { |change| change[:setting] == :enable_upload_debug_mode },
+ ).not_to be_present
+ expect(results.find { |change| change[:setting] == :allow_user_locale }).to be_present
+ end
+ end
end
it "updates the user's last_visited_upcoming_changes_at custom field" do
diff --git a/spec/system/admin_upcoming_changes_spec.rb b/spec/system/admin_upcoming_changes_spec.rb
index 9faf9a96f8a..ee706eb3d8a 100644
--- a/spec/system/admin_upcoming_changes_spec.rb
+++ b/spec/system/admin_upcoming_changes_spec.rb
@@ -62,6 +62,22 @@ describe "Admin upcoming changes" do
expect(upcoming_changes_page).to have_no_change(:about_page_extra_groups_show_description)
end
+ it "does not show permanent upcoming changes" do
+ mock_upcoming_change_metadata(
+ {
+ allow_uppercase_posts: {
+ impact: "feature,all_members",
+ status: :permanent,
+ impact_type: "feature",
+ impact_role: "all_members",
+ },
+ },
+ )
+
+ upcoming_changes_page.visit
+ expect(upcoming_changes_page).to have_no_change(:allow_uppercase_posts)
+ end
+
# NOTE (martin): Skipped for now because it is flaky on CI, it will be something to do with the
# sample plugin settings loaded in the SiteSetting model.
xit "shows upcoming changes from plugins" do
diff --git a/spec/system/admin_whats_new_spec.rb b/spec/system/admin_whats_new_spec.rb
index a49c97c69fb..5c62021d172 100644
--- a/spec/system/admin_whats_new_spec.rb
+++ b/spec/system/admin_whats_new_spec.rb
@@ -10,12 +10,12 @@ describe "Admin What's New Page" do
sign_in(admin)
end
- def set_new_features_payload(payload)
+ def set_new_features_response_json(payload)
Discourse.redis.set("new_features", MultiJson.dump(payload))
end
it "shows an error message when the backend returns an empty list" do
- set_new_features_payload(nil)
+ set_new_features_response_json(nil)
whats_new_page.visit
expect(whats_new_page).to have_content(
html_translation_to_text(
@@ -26,7 +26,7 @@ describe "Admin What's New Page" do
it "displays a new feature indicator on the sidebar and clears it when navigating to what's new" do
DiscourseUpdates.stubs(:has_unseen_features?).returns(true)
- set_new_features_payload(
+ set_new_features_response_json(
[
{
"id" => 7,
@@ -56,7 +56,7 @@ describe "Admin What's New Page" do
end
it "displays new features with screenshot taking precedence over emoji" do
- set_new_features_payload(
+ set_new_features_response_json(
[
{
"id" => 7,
@@ -108,7 +108,7 @@ describe "Admin What's New Page" do
end
it "displays new features with emoji when no screenshot" do
- set_new_features_payload(
+ set_new_features_response_json(
[
{
"id" => 7,
@@ -125,7 +125,9 @@ describe "Admin What's New Page" do
],
)
whats_new_page.visit
- expect(whats_new_page).to have_emoji
- expect(whats_new_page).to have_no_screenshot
+ whats_new_page.within_new_feature_item("New feature") do
+ expect(whats_new_page).to have_emoji
+ expect(whats_new_page).to have_no_screenshot
+ end
end
end