A platform for community discussion. Free, open, simple.
DEV: Remove child theme settings/variables from parent compilation (#16001)
David Taylor5d6d3fb24404
diff --git a/app/models/theme.rb b/app/models/theme.rbindex 0f57ae5e537..b2d867509c9 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -470,16 +470,6 @@ class Theme < ActiveRecord::Baseendend- def all_theme_variables- fields = {}- ids = Theme.transform_ids(id)- ThemeField.find_by_theme_ids(ids).where(type_id: ThemeField.theme_var_type_ids).each do |field|- next if fields.key?(field.name)- fields[field.name] = field- end- fields.values- end-def add_relative_theme!(kind, theme)new_relation = if kind == :childchild_theme_relation.new(child_theme_id: theme.id)@@ -559,17 +549,6 @@ class Theme < ActiveRecord::Basehashend- def included_settings- hash = {}-- Theme.where(id: Theme.transform_ids(id)).each do |theme|- hash.merge!(theme.build_settings_hash)- end-- hash.merge!(self.build_settings_hash)- hash- end-def update_setting(setting_name, new_value)target_setting = settings.find { |setting| setting.name == setting_name }raise Discourse::NotFound unless target_setting@@ -654,11 +633,14 @@ class Theme < ActiveRecord::Baseenddef scss_variables- return if all_theme_variables.empty? && included_settings.empty?+ settings_hash = build_settings_hash+ theme_variable_fields = var_theme_fields++ return if theme_variable_fields.empty? && settings_hash.empty?contents = +""- all_theme_variables&.each do |field|+ theme_variable_fields&.each do |field|if field.type_id == ThemeField.types[:theme_upload_var]if upload = field.uploadurl = upload_cdn_path(upload.url)@@ -669,7 +651,7 @@ class Theme < ActiveRecord::Baseendend- included_settings&.each do |name, value|+ settings_hash&.each do |name, value|next if name == "theme_uploads"contents << to_scss_variable(name, value)enddiff --git a/spec/models/theme_spec.rb b/spec/models/theme_spec.rbindex 04f2a441a26..50424e2c477 100644--- a/spec/models/theme_spec.rb+++ b/spec/models/theme_spec.rb@@ -565,36 +565,6 @@ HTMLexpect(json["my_upload"]).to eq("http://cdn.localhost#{upload.url}")end- it 'handles child settings correctly' do- Theme.destroy_all-- expect(included_settings(theme.id)).to eq("{}")-- theme.set_field(target: :settings, name: "yaml", value: "boolean_setting: true")- theme.save!- expect(included_settings(theme.id)).to match(/\"boolean_setting\":true/)-- theme.settings.first.value = "false"- theme.save!- expect(included_settings(theme.id)).to match(/\"boolean_setting\":false/)-- child.set_field(target: :settings, name: "yaml", value: "integer_setting: 54")-- child.save!- theme.add_relative_theme!(:child, child)-- json = included_settings(theme.id)- expect(json).to match(/\"boolean_setting\":false/)- expect(json).to match(/\"integer_setting\":54/)-- expect(included_settings(child.id)).to eq("{\"integer_setting\":54}")-- child.destroy!- json = included_settings(theme.id)- expect(json).not_to match(/\"integer_setting\":54/)- expect(json).to match(/\"boolean_setting\":false/)- end-describe "convert_settings" doit 'can migrate a list field to a string field with json schema' dodiff --git a/spec/requests/admin/themes_controller_spec.rb b/spec/requests/admin/themes_controller_spec.rbindex 391eb2290f5..6c31f6ea1d1 100644--- a/spec/requests/admin/themes_controller_spec.rb+++ b/spec/requests/admin/themes_controller_spec.rb@@ -650,7 +650,7 @@ describe Admin::ThemesController doexpect(response.parsed_body["bg"]).to eq("green")theme.reload- expect(theme.included_settings[:bg]).to eq("green")+ expect(theme.cached_settings[:bg]).to eq("green")user_history = UserHistory.lastexpect(user_history.action).to eq(@@ -663,7 +663,7 @@ describe Admin::ThemesController dotheme.reloadexpect(response.status).to eq(200)- expect(theme.included_settings[:bg]).to eq("")+ expect(theme.cached_settings[:bg]).to eq("")endendend