FEATURE: allow disabling theme components (#7812)

This allows you to temporarily disable components without having to remove them from a theme. 

This feature is very handy when doing quick fix engineering.
This commit is contained in:
Osama Sayegh
2019-07-03 11:18:11 +03:00
committed by Sam
parent ecf0215ee7
commit 3d64532273
15 changed files with 238 additions and 16 deletions

View File

@@ -156,8 +156,10 @@ class Admin::ThemesController < Admin::AdminController
raise Discourse::InvalidParameters.new(:id) unless @theme
original_json = ThemeSerializer.new(@theme, root: false).to_json
disables_component = [false, "false"].include?(theme_params[:enabled])
enables_component = [true, "true"].include?(theme_params[:enabled])
[:name, :color_scheme_id, :user_selectable].each do |field|
[:name, :color_scheme_id, :user_selectable, :enabled].each do |field|
if theme_params.key?(field)
@theme.public_send("#{field}=", theme_params[field])
end
@@ -203,7 +205,13 @@ class Admin::ThemesController < Admin::AdminController
update_default_theme
@theme.reload
log_theme_change(original_json, @theme)
if (!disables_component && !enables_component) || theme_params.keys.size > 1
log_theme_change(original_json, @theme)
end
log_theme_component_disabled if disables_component
log_theme_component_enabled if enables_component
format.json { render json: @theme, status: :ok }
else
format.json do
@@ -304,6 +312,7 @@ class Admin::ThemesController < Admin::AdminController
:default,
:user_selectable,
:component,
:enabled,
settings: {},
translations: {},
theme_fields: [:name, :target, :value, :upload_id, :type_id],
@@ -350,6 +359,14 @@ class Admin::ThemesController < Admin::AdminController
StaffActionLogger.new(current_user).log_theme_setting_change(setting_name, previous_value, new_value, @theme)
end
def log_theme_component_disabled
StaffActionLogger.new(current_user).log_theme_component_disabled(@theme)
end
def log_theme_component_enabled
StaffActionLogger.new(current_user).log_theme_component_enabled(@theme)
end
def handle_switch
param = theme_params[:component]
if param.to_s == "false" && @theme.component?