mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Display errors in single theme pages (#6449)
Currently the errors are not well handled. So it breaks the whole UI of admin themes list page.
This commit is contained in:
parent
b5bdd42838
commit
a651d39b8a
@ -9,6 +9,13 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</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}}
|
{{#if model.remote_theme}}
|
||||||
<a class="url about-url" href="{{model.remote_theme.about_url}}">{{i18n "admin.customize.theme.about_theme"}}</a>
|
<a class="url about-url" href="{{model.remote_theme.about_url}}">{{i18n "admin.customize.theme.about_theme"}}</a>
|
||||||
{{#if model.remote_theme.license_url}}
|
{{#if model.remote_theme.license_url}}
|
||||||
|
@ -61,7 +61,7 @@ class RemoteThemeSerializer < ApplicationSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ThemeSerializer < ChildThemeSerializer
|
class 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, :errors
|
||||||
|
|
||||||
has_one :user, serializer: UserNameSerializer, embed: :object
|
has_one :user, serializer: UserNameSerializer, embed: :object
|
||||||
|
|
||||||
@ -69,17 +69,33 @@ class ThemeSerializer < ChildThemeSerializer
|
|||||||
has_many :child_themes, serializer: ChildThemeSerializer, embed: :objects
|
has_many :child_themes, serializer: ChildThemeSerializer, embed: :objects
|
||||||
has_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects
|
has_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects
|
||||||
|
|
||||||
|
def initialize(theme, options = {})
|
||||||
|
super
|
||||||
|
@errors = []
|
||||||
|
end
|
||||||
|
|
||||||
def child_themes
|
def child_themes
|
||||||
object.child_themes.order(:name)
|
object.child_themes.order(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings
|
def settings
|
||||||
object.settings.map { |setting| ThemeSettingsSerializer.new(setting, root: false) }
|
object.settings.map { |setting| ThemeSettingsSerializer.new(setting, root: false) }
|
||||||
|
rescue ThemeSettingsParser::InvalidYaml => e
|
||||||
|
@errors << e.message
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_child_themes?
|
def include_child_themes?
|
||||||
!object.component?
|
!object.component?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def errors
|
||||||
|
@errors
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_errors?
|
||||||
|
@errors.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class ThemeFieldWithEmbeddedUploadsSerializer < ThemeFieldSerializer
|
class ThemeFieldWithEmbeddedUploadsSerializer < ThemeFieldSerializer
|
||||||
|
14
spec/serializers/theme_serializer_spec.rb
Normal file
14
spec/serializers/theme_serializer_spec.rb
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user