mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 07:14:41 +08:00
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:
@ -322,6 +322,65 @@ describe Admin::ThemesController do
|
||||
expect(theme.theme_translation_overrides.count).to eq(0)
|
||||
end
|
||||
|
||||
it 'can disable component' do
|
||||
child = Fabricate(:theme, component: true)
|
||||
|
||||
put "/admin/themes/#{child.id}.json", params: {
|
||||
theme: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
expect(json["theme"]["enabled"]).to eq(false)
|
||||
expect(UserHistory.where(
|
||||
context: child.id.to_s,
|
||||
action: UserHistory.actions[:disable_theme_component]
|
||||
).size).to eq(1)
|
||||
expect(json["theme"]["disabled_by"]["id"]).to eq(admin.id)
|
||||
end
|
||||
|
||||
it "enabling/disabling a component creates the correct staff action log" do
|
||||
child = Fabricate(:theme, component: true)
|
||||
UserHistory.destroy_all
|
||||
|
||||
put "/admin/themes/#{child.id}.json", params: {
|
||||
theme: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
expect(UserHistory.where(
|
||||
context: child.id.to_s,
|
||||
action: UserHistory.actions[:disable_theme_component]
|
||||
).size).to eq(1)
|
||||
expect(UserHistory.where(
|
||||
context: child.id.to_s,
|
||||
action: UserHistory.actions[:enable_theme_component]
|
||||
).size).to eq(0)
|
||||
|
||||
put "/admin/themes/#{child.id}.json", params: {
|
||||
theme: {
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
||||
expect(UserHistory.where(
|
||||
context: child.id.to_s,
|
||||
action: UserHistory.actions[:disable_theme_component]
|
||||
).size).to eq(1)
|
||||
expect(UserHistory.where(
|
||||
context: child.id.to_s,
|
||||
action: UserHistory.actions[:enable_theme_component]
|
||||
).size).to eq(1)
|
||||
|
||||
expect(json["theme"]["disabled_by"]).to eq(nil)
|
||||
expect(json["theme"]["enabled"]).to eq(true)
|
||||
end
|
||||
|
||||
it 'handles import errors on update' do
|
||||
theme.create_remote_theme!(remote_url: "https://example.com/repository")
|
||||
|
||||
|
Reference in New Issue
Block a user