mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-01 12:58:30 +08:00
This PR introduces part one of the "Upcoming changes" interface for Discourse admins. The upcoming changes feature is an enhancement around our existing site-setting based feature flagging and experiments system. With some light metadata, we can give admins a much better overview of the current work we are doing, with ways for them to opt-out in early stages and opt-in to things that we haven’t yet turned on by default for them. This system, along with encouraging a more liberal use of site setting flags for features, experiments, and refactors in the app, should minimise the problem of breakages and disruptions for all Discourse users. It is also our intent with this system for it to be easier for designers to add and remove these changes. Finally, it also gives us a kind of running changelog that we can use to communicate with site owners before releases and “What’s new?” updates. ### FOR REVIEWERS This initial PR is gated behind a hidden `enable_upcoming_changes` site setting, because there is still more work to do before we reveal this to admins. To test the UI, you can add this metadata under any boolean-based site setting, though upcoming change settings will specifically be hidden: ``` upcoming_change: status: "alpha" (see UpcomingChanges.statuses.keys) impact: "feature,staff" (feature|other for the first part, staff|admins|moderators|all_members|developers for the second part) learn_more_url: "https://some.url" ``` To test the images, add an image under `public/images/upcoming_changes` with the file name as `SITE_SETTING_NAME.png` ### Interface Admins can see the following in the interface for upcoming changes: * The status of the change. Changes can progress along these statuses: * Pre-Alpha * Alpha * Beta * Stable * Permanent * The impact of the change. This is split into Type and Role. Type can be "Feature" or "Other" for now. Changes may affect the following roles: * Admins * Moderators * Staff * All members * The plugin that is making the change * The groups that are opted-in to the change. Admins can control these groups for a gradual rollout. If a change is enabled, it is limited to these groups. * In some cases, an image related to the change, behind the "Preview" link * A link to learn more about the change Admins can filter the changes by name, description, plugin, status, impact type, and whether the change is enabled. ### Promotion system For our hosted customers, we intend to have a status-based auto-promotion system as changes progress. For all sites, once a change reaches the Stable status, if an admin opts-out of that change it will generate an admin problem message that will be shown on the dashboard. For self-hosted Discourse admins, changes will only be forcibly enabled when they reach the Permanent state. ### Notification system A notification system for upcoming changes so admins can stay informed will be added in a followup PR. --------- Co-authored-by: awesomerobot <kris.aubuchon@discourse.org>
80 lines
1.9 KiB
Ruby
80 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class SiteSetting::UpsertGroups
|
|
include Service::Base
|
|
|
|
params do
|
|
before_validation { self.group_names = Array.wrap(self.group_names).delete_if(&:empty?) }
|
|
|
|
attribute :group_names, :array
|
|
attribute :setting, :string
|
|
|
|
validates :setting, presence: true
|
|
end
|
|
|
|
policy :current_user_is_admin
|
|
only_if(:provided_group_names) do
|
|
model :group_ids
|
|
|
|
transaction do
|
|
step :upsert_site_setting_groups
|
|
step :log_site_setting_groups_change
|
|
end
|
|
end
|
|
only_if(:no_provided_group_names) do
|
|
transaction do
|
|
step :delete_site_setting_group
|
|
step :log_site_setting_groups_change
|
|
end
|
|
end
|
|
step :notify_changed
|
|
|
|
private
|
|
|
|
def provided_group_names(params:)
|
|
params.group_names.present?
|
|
end
|
|
|
|
def no_provided_group_names(params:)
|
|
!provided_group_names(params:)
|
|
end
|
|
|
|
def current_user_is_admin(guardian:)
|
|
guardian.is_admin?
|
|
end
|
|
|
|
def fetch_group_ids(params:)
|
|
Group.where(name: params.group_names).pluck(:id)
|
|
end
|
|
|
|
def upsert_site_setting_groups(params:, group_ids:, guardian:)
|
|
context[:previous_value] = SiteSettingGroup.find_by(name: params.setting)&.group_ids
|
|
context[:new_value] = group_ids.sort.join("|")
|
|
|
|
SiteSettingGroup.upsert(
|
|
{ name: params.setting, group_ids: context[:new_value] },
|
|
unique_by: :name,
|
|
)
|
|
end
|
|
|
|
def delete_site_setting_group(params:, guardian:)
|
|
previous_record = SiteSettingGroup.find_by(name: params.setting)
|
|
context[:previous_value] = previous_record&.group_ids
|
|
context[:new_value] = ""
|
|
|
|
previous_record&.destroy!
|
|
end
|
|
|
|
def log_site_setting_groups_change(params:, guardian:, new_value:, previous_value:)
|
|
StaffActionLogger.new(guardian.user).log_site_setting_groups_change(
|
|
params.setting,
|
|
previous_value,
|
|
new_value,
|
|
)
|
|
end
|
|
|
|
def notify_changed
|
|
SiteSetting.refresh_site_setting_group_ids!
|
|
SiteSetting.notify_changed!
|
|
end
|
|
end
|