FIX: Display proper error message when changing a trust level fails

This commit is contained in:
Robin Ward 2014-07-29 15:54:20 -04:00
parent 55457810ba
commit ac4a33a656
2 changed files with 7 additions and 1 deletions

View file

@ -155,7 +155,11 @@ Discourse.AdminUser = Discourse.User.extend({
window.location.reload();
}, function(e) {
// failure
var error = I18n.t('admin.user.trust_level_change_failed', { error: "http: " + e.status + " - " + e.body });
var error;
if (e.responseJSON && e.responseJSON.errors) {
error = e.responseJSON.errors[0];
}
error = error || I18n.t('admin.user.trust_level_change_failed', { error: "http: " + e.status + " - " + e.body });
bootbox.alert(error);
});
},

View file

@ -131,6 +131,8 @@ class Admin::UsersController < Admin::AdminController
@user.change_trust_level!(level, log_action_for: current_user)
render_serialized(@user, AdminUserSerializer)
rescue Discourse::InvalidAccess => e
render_json_error(e.message)
end
def approve