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

This results in some fun disasters if allowed to happen. For now, just issue an oblique error message; a localized message will be added on the client.
This commit is contained in:
Kane York 2021-01-11 14:53:04 -08:00 committed by Kane York
parent bd25627198
commit e96c373f3a
2 changed files with 14 additions and 0 deletions

View File

@ -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" && !@theme.component?
raise Discourse::InvalidParameters.new(:component) if @theme.id == SiteSetting.default_theme_id
@theme.switch_to_component!
end
end

View File

@ -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