mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:50:26 -06:00
FIX: better error handling for theme import
This commit is contained in:
parent
5e3a0846f7
commit
86904e9cd6
@ -1,5 +1,6 @@
|
||||
import { default as computed } from 'ember-addons/ember-computed-decorators';
|
||||
import { url } from 'discourse/lib/computed';
|
||||
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
|
||||
@ -79,16 +80,20 @@ export default Ember.Controller.extend({
|
||||
|
||||
updateToLatest() {
|
||||
this.set("updatingRemote", true);
|
||||
this.get("model").updateToLatest().finally(()=>{
|
||||
this.set("updatingRemote", false);
|
||||
});
|
||||
this.get("model").updateToLatest()
|
||||
.catch(popupAjaxError)
|
||||
.finally(()=>{
|
||||
this.set("updatingRemote", false);
|
||||
});
|
||||
},
|
||||
|
||||
checkForThemeUpdates() {
|
||||
this.set("updatingRemote", true);
|
||||
this.get("model").checkForUpdates().finally(()=>{
|
||||
this.set("updatingRemote", false);
|
||||
});
|
||||
this.get("model").checkForUpdates()
|
||||
.catch(popupAjaxError)
|
||||
.finally(()=>{
|
||||
this.set("updatingRemote", false);
|
||||
});
|
||||
},
|
||||
|
||||
cancelChangeScheme() {
|
||||
|
@ -65,7 +65,7 @@
|
||||
<p>
|
||||
{{#if model.remote_theme}}
|
||||
{{#if model.remote_theme.commits_behind}}
|
||||
{{#d-button action="updateToLatest" icon="download"}}{{i18n "admin.customize.theme.update_to_latest"}}{{/d-button}}
|
||||
{{#d-button action="updateToLatest" icon="download" class='btn-primary'}}{{i18n "admin.customize.theme.update_to_latest"}}{{/d-button}}
|
||||
{{else}}
|
||||
{{#d-button action="checkForThemeUpdates" icon="refresh"}}{{i18n "admin.customize.theme.check_for_updates"}}{{/d-button}}
|
||||
{{/if}}
|
||||
|
@ -101,25 +101,32 @@ class Admin::ThemesController < Admin::AdminController
|
||||
|
||||
set_fields
|
||||
|
||||
save_remote = false
|
||||
if params[:theme][:remote_check]
|
||||
@theme.remote_theme.update_remote_version
|
||||
@theme.remote_theme.save!
|
||||
save_remote = true
|
||||
end
|
||||
|
||||
if params[:theme][:remote_update]
|
||||
@theme.remote_theme.update_from_remote
|
||||
@theme.remote_theme.save!
|
||||
save_remote = true
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
if @theme.save
|
||||
|
||||
@theme.remote_theme.save! if save_remote
|
||||
|
||||
update_default_theme
|
||||
|
||||
log_theme_change(original_json, @theme)
|
||||
format.json { render json: @theme, status: :created}
|
||||
else
|
||||
format.json { render json: @theme.errors, status: :unprocessable_entity }
|
||||
format.json {
|
||||
|
||||
error = @theme.errors[:color_scheme] ? I18n.t("themes.bad_color_scheme") : I18n.t("themes.other_error")
|
||||
render json: {errors: [ error ]}, status: :unprocessable_entity
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -82,7 +82,7 @@ class RemoteTheme < ActiveRecord::Base
|
||||
return unless hex
|
||||
|
||||
override = hex.downcase
|
||||
if override !~ /[0-9a-f]{6}/
|
||||
if override !~ /^[0-9a-f]{6}$/
|
||||
override = nil
|
||||
end
|
||||
override
|
||||
|
@ -55,6 +55,9 @@ en:
|
||||
anonymous: "Anonymous"
|
||||
remove_posts_deleted_by_author: "Deleted by author"
|
||||
|
||||
themes:
|
||||
bad_color_scheme: "Can not update theme, invalid color scheme"
|
||||
other_error: "Something went wrong updating theme"
|
||||
emails:
|
||||
incoming:
|
||||
default_subject: "This topic needs a title"
|
||||
|
Loading…
Reference in New Issue
Block a user