A platform for community discussion. Free, open, simple.
FIX: Display errors in single theme pages (#6449)
Vinoth Kannana651d39b8a13
diff --git a/app/assets/javascripts/admin/templates/customize-themes-show.hbs b/app/assets/javascripts/admin/templates/customize-themes-show.hbsindex fcddcfa165c..c957a44c47e 100644--- a/app/assets/javascripts/admin/templates/customize-themes-show.hbs+++ b/app/assets/javascripts/admin/templates/customize-themes-show.hbs@@ -9,6 +9,13 @@{{/if}}</div>+ {{#each model.errors as |error|}}+ <div class="alert alert-error">+ <button class="close" data-dismiss="alert">×</button>+ {{error}}+ </div>+ {{/each}}+{{#if model.remote_theme}}<a class="url about-url" href="{{model.remote_theme.about_url}}">{{i18n "admin.customize.theme.about_theme"}}</a>{{#if model.remote_theme.license_url}}diff --git a/app/serializers/theme_serializer.rb b/app/serializers/theme_serializer.rbindex 0e8291cea77..41dfe0120d6 100644--- a/app/serializers/theme_serializer.rb+++ b/app/serializers/theme_serializer.rb@@ -61,7 +61,7 @@ class RemoteThemeSerializer < ApplicationSerializerendclass ThemeSerializer < ChildThemeSerializer- attributes :color_scheme, :color_scheme_id, :user_selectable, :remote_theme_id, :settings+ attributes :color_scheme, :color_scheme_id, :user_selectable, :remote_theme_id, :settings, :errorshas_one :user, serializer: UserNameSerializer, embed: :object@@ -69,17 +69,33 @@ class ThemeSerializer < ChildThemeSerializerhas_many :child_themes, serializer: ChildThemeSerializer, embed: :objectshas_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects+ def initialize(theme, options = {})+ super+ @errors = []+ end+def child_themesobject.child_themes.order(:name)enddef settingsobject.settings.map { |setting| ThemeSettingsSerializer.new(setting, root: false) }+ rescue ThemeSettingsParser::InvalidYaml => e+ @errors << e.message+ nilenddef include_child_themes?!object.component?end++ def errors+ @errors+ end++ def include_errors?+ @errors.present?+ endendclass ThemeFieldWithEmbeddedUploadsSerializer < ThemeFieldSerializerdiff --git a/spec/serializers/theme_serializer_spec.rb b/spec/serializers/theme_serializer_spec.rbnew file mode 100644index 00000000000..2e84cae38f8--- /dev/null+++ b/spec/serializers/theme_serializer_spec.rb@@ -0,0 +1,14 @@+require 'rails_helper'++RSpec.describe ThemeSerializer do+ describe "load theme settings" do+ it 'should add error message when having invalid format' do+ theme = Fabricate(:theme)+ Theme.any_instance.stubs(:settings).raises(ThemeSettingsParser::InvalidYaml, I18n.t("themes.settings_errors.invalid_yaml"))+ serialized = ThemeSerializer.new(theme).as_json[:theme]+ expect(serialized[:settings]).to be_nil+ expect(serialized[:errors].count).to eq(1)+ expect(serialized[:errors][0]).to eq(I18n.t("themes.settings_errors.invalid_yaml"))+ end+ end+end