FIX: When running the wizard and using a custom theme, fallback to the color_scheme name if the base_scheme_id is nil (#8236)
This commit is contained in:
parent
5ae35f9906
commit
070a3dcf9b
|
@ -187,6 +187,10 @@ class ColorScheme < ActiveRecord::Base
|
||||||
@base_color_scheme
|
@base_color_scheme
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.is_base?(scheme_name)
|
||||||
|
base_color_scheme_colors.map { |c| c[:id] }.include?(scheme_name)
|
||||||
|
end
|
||||||
|
|
||||||
# create_from_base will create a new ColorScheme that overrides Discourse's base color scheme with the given colors.
|
# create_from_base will create a new ColorScheme that overrides Discourse's base color scheme with the given colors.
|
||||||
def self.create_from_base(params)
|
def self.create_from_base(params)
|
||||||
new_color_scheme = new(name: params[:name])
|
new_color_scheme = new(name: params[:name])
|
||||||
|
|
|
@ -146,12 +146,10 @@ class Wizard
|
||||||
default_theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
default_theme = Theme.find_by(id: SiteSetting.default_theme_id)
|
||||||
default_theme_override = SiteSetting.exists?(name: "default_theme_id")
|
default_theme_override = SiteSetting.exists?(name: "default_theme_id")
|
||||||
|
|
||||||
scheme_id =
|
base_scheme = default_theme&.color_scheme&.base_scheme_id
|
||||||
if default_theme_override
|
color_scheme_name = default_theme&.color_scheme&.name
|
||||||
default_theme&.color_scheme&.base_scheme_id
|
|
||||||
else
|
scheme_id = default_theme_override ? (base_scheme || color_scheme_name) : ColorScheme::LIGHT_THEME_ID
|
||||||
ColorScheme::LIGHT_THEME_ID
|
|
||||||
end
|
|
||||||
|
|
||||||
themes = step.add_field(
|
themes = step.add_field(
|
||||||
id: 'theme_previews',
|
id: 'theme_previews',
|
||||||
|
@ -160,6 +158,14 @@ class Wizard
|
||||||
value: scheme_id
|
value: scheme_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# fix for the case when base_scheme is nil
|
||||||
|
if scheme_id && default_theme_override && base_scheme.nil?
|
||||||
|
scheme = default_theme.color_scheme
|
||||||
|
default_colors = scheme.colors.select(:name, :hex)
|
||||||
|
choice_hash = default_colors.reduce({}) { |choice, color| choice[color.name] = "##{color.hex}"; choice }
|
||||||
|
themes.add_choice(scheme_id, data: { colors: choice_hash })
|
||||||
|
end
|
||||||
|
|
||||||
ColorScheme.base_color_scheme_colors.each do |t|
|
ColorScheme.base_color_scheme_colors.each do |t|
|
||||||
with_hash = t[:colors].dup
|
with_hash = t[:colors].dup
|
||||||
with_hash.map { |k, v| with_hash[k] = "##{v}" }
|
with_hash.map { |k, v| with_hash[k] = "##{v}" }
|
||||||
|
@ -172,7 +178,7 @@ class Wizard
|
||||||
ColorScheme::LIGHT_THEME_ID
|
ColorScheme::LIGHT_THEME_ID
|
||||||
)
|
)
|
||||||
|
|
||||||
next unless scheme_name.present?
|
next unless scheme_name.present? && ColorScheme.is_base?(scheme_name)
|
||||||
|
|
||||||
name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(' ', '_')}_theme_name")
|
name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(' ', '_')}_theme_name")
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,21 @@ describe Wizard::Builder do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "when the default them hass been override" do
|
describe "when the default theme has been override and the color scheme doesn't have a base scheme" do
|
||||||
|
let(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: nil) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
SiteSetting.default_theme_id = theme.id
|
||||||
|
theme.update(color_scheme: color_scheme)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fallbacks to the color scheme name' do
|
||||||
|
expect(field.required).to eq(false)
|
||||||
|
expect(field.value).to eq(color_scheme.name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "when the default theme has been override" do
|
||||||
before do
|
before do
|
||||||
theme.set_default!
|
theme.set_default!
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue