mirror of
https://github.com/discourse/discourse.git
synced 2026-08-08 17:53:55 +08:00
DesignWizard::Apply set site settings itself via set_and_log, then hand-rolled an after_rollback callback to put the in-process SiteSetting cache back if a later write blew up. That compensation only ever fired if a third-party :site_setting_changed subscriber raised — already an unhandled 500 — and half of it was dead code, since after_rollback runs once the site_settings rows have already been reverted. It also forced transaction(requires_new: true), which meant a savepoint whose only purpose was to make the callback fire under transactional fixtures. Delegate to SiteSetting::Update instead. It brings type coercion, dependency ordering, and the deprecation/shadowing/visibility/configurability policies — notably fixing a case where the wizard reported success but silently did nothing when default_theme_id was shadowed by a GlobalSetting. It opens its own transaction, so the step moves out of ours, which now wraps only the theme and palette writes. default_theme_id is hidden, so it's passed via allow_changing_hidden. Also extracts the palette selectability writes into a dedicated action, and reverts the transaction option plumbing added to the service base, which no longer has a caller.
36 lines
1.1 KiB
Ruby
Vendored
36 lines
1.1 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
# Every save re-states the whole offering, so palettes an admin made selectable
|
|
# outside the wizard are reset too.
|
|
#
|
|
# update_all skips callbacks deliberately: user_selectable does not affect
|
|
# compiled CSS, and the caller expires the one cache that matters. ColorScheme's
|
|
# default scope excludes remote copies, which is what keeps this from bypassing
|
|
# no_edits_for_remote_copies.
|
|
class DesignWizard::Action::UpdatePaletteSelectability < Service::ActionBase
|
|
option :theme
|
|
option :selectable
|
|
|
|
def call
|
|
revoke_palettes_no_longer_offered
|
|
offered.update_all(user_selectable: selectable)
|
|
end
|
|
|
|
private
|
|
|
|
def offered
|
|
@offered ||=
|
|
begin
|
|
theme_palettes = ColorScheme.where(theme_id: theme.id)
|
|
theme_palettes.none? ? ColorScheme.where(via_wizard: true) : theme_palettes
|
|
end
|
|
end
|
|
|
|
def revoke_palettes_no_longer_offered
|
|
ColorScheme
|
|
.where(theme_id: Theme::CORE_THEMES.values)
|
|
.or(ColorScheme.where(via_wizard: true))
|
|
.where.not(id: offered.select(:id))
|
|
.update_all(user_selectable: false)
|
|
end
|
|
end
|