mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
This commit adds several pieces of functionality to help keep admins in the loop about upcoming changes. First of all, there is a new initializer on boot that will notify admins about newly available upcoming changes, as well as log removed changes and status movement of existing changes. * When there is a new upcoming change, we only notify admins about it when the status is the `promote_upcoming_changes_on_status` - 1, e.g. if `promote_upcoming_changes_on_status` is `beta` then we only tell admin about the change once it has reached `alpha`. This means we may log the `added` event in one deploy, but only actually notify admins in a subsequent deploy. * We log removed upcoming changes so we can automatically delete old site setting data in a future job as needed. We also now notify admins when upcoming changes are automatically promoted to enabled based on the site's `promote_upcoming_changes_on_status`: <img width="378" height="600" alt="image" src="https://github.com/user-attachments/assets/4200fbee-9990-4bbc-a378-85946e631e77" /> In addition, we now show an indicator in the admin sidebar if there are new upcoming changes that have been added since they last visited the upcoming change config page. This data is stored in a user custom field, because Redis is ephemeral, and storing in the User table is overkill because 99% of users are not staff: <img width="248" height="112" alt="image" src="https://github.com/user-attachments/assets/4c3d3cf7-ac39-45f8-a2c8-a049cb85b8e9" /> Finally, this commit moves both the Track and Promote initializer logic behind a `DistributedMutex`, we don't want multiple processes running the same logic here, it needs to be only once. --------- Co-authored-by: Loïc Guitaut <loic@discourse.org> Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
65 lines
2.2 KiB
Ruby
Vendored
65 lines
2.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module UpcomingChanges
|
|
class TrackingInitializer
|
|
def self.log_prefix(site)
|
|
"[Upcoming changes tracker (#{site})]: "
|
|
end
|
|
|
|
def self.verbose_log(site, level, message)
|
|
return unless SiteSetting.upcoming_change_verbose_logging
|
|
Rails.logger.public_send(level, "#{log_prefix(site)} #{message}")
|
|
end
|
|
|
|
def self.call
|
|
RailsMultisite::ConnectionManagement.safe_each_connection do |site|
|
|
next if !SiteSetting.enable_upcoming_changes
|
|
|
|
verbose_log(site, :info, "Beginning tracking initializer for upcoming changes")
|
|
|
|
if SiteSetting.upcoming_change_site_settings.empty?
|
|
verbose_log(site, :info, "No upcoming changes present.")
|
|
next
|
|
end
|
|
|
|
DistributedMutex.synchronize("track_upcoming_changes_#{site}") do
|
|
UpcomingChanges::Track.call(guardian: Guardian.new(Discourse.system_user)) do |result|
|
|
on_success do |added_changes:, removed_changes:, notified_admins_for_added_changes:, status_changes:|
|
|
added_changes.each do |change_name|
|
|
verbose_log(site, :info, "added upcoming change '#{change_name}'")
|
|
end
|
|
|
|
notified_admins_for_added_changes.each do |change_name|
|
|
verbose_log(
|
|
site,
|
|
:info,
|
|
"notified site admins about added upcoming change '#{change_name}'",
|
|
)
|
|
end
|
|
|
|
removed_changes.each do |change_name|
|
|
verbose_log(site, :info, "removed upcoming change '#{change_name}'")
|
|
end
|
|
|
|
status_changes.each do |change_name, details|
|
|
verbose_log(
|
|
site,
|
|
:info,
|
|
"status changed for upcoming change '#{change_name}' from #{details[:previous_value]} to #{details[:new_value]}",
|
|
)
|
|
end
|
|
end
|
|
|
|
on_failure do |error|
|
|
verbose_log(
|
|
site,
|
|
:error,
|
|
"Failed to track upcoming changes', an unexpected error occurred. Error: #{error&.backtrace&.join("\n")}",
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|