mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 01:45:44 +08:00
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:
parent
bd25627198
commit
e96c373f3a
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user