Skip to content

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

FIX: Prevent users from converting the default theme to a component

Kane Yorke96c373f3ac8
diff --git a/app/controllers/admin/themes_controller.rb b/app/controllers/admin/themes_controller.rb
index a322918dbcb..82d00fa26c3 100644
--- a/app/controllers/admin/themes_controller.rb
+++ b/app/controllers/admin/themes_controller.rb
@@ -401,8 +401,10 @@ class Admin::ThemesController < Admin::AdminController
def handle_switch
param = theme_params[:component]
if param.to_s == "false" && @theme.component?
+ raise Discourse::InvalidParameters.new(:component) if @theme.id == SiteSetting.default_theme_id
@theme.switch_to_theme!
elsif param.to_s == "true" && [email protected]?
+ raise Discourse::InvalidParameters.new(:component) if @theme.id == SiteSetting.default_theme_id
@theme.switch_to_component!
end
end
diff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rb
index 36f7c97ad7e..b01ed754330 100644
--- a/spec/requests/admin/themes_controller_spec.rb
+++ b/spec/requests/admin/themes_controller_spec.rb
@@ -551,6 +551,18 @@ describe Admin::ThemesController do
expect(response.status).to eq(400)
expect(response.parsed_body["errors"].first).to include(I18n.t("themes.errors.component_no_default"))
end
+
+ it 'prevents converting the default theme to a component' do
+ SiteSetting.default_theme_id = theme.id
+
+ put "/admin/themes/#{theme.id}.json", params: {
+ theme: { component: true }
+ }
+
+ # should this error message be localized? InvalidParameters :component
+ expect(response.status).to eq(400)
+ expect(response.parsed_body["errors"].first).to include('component')
+ end
end
describe '#destroy' do