User admin: properly handle AJAX errors.
Added specific handling for clicking on non-existing users. The styling might need some tweaking (it's pretty ugly), but then again, it's just for us admins.
This commit is contained in:
parent
486686f1f9
commit
3bb55fd3db
@ -6,6 +6,8 @@ from flask import (abort, Blueprint, current_app, flash, redirect,
|
||||
render_template, request, session, url_for)
|
||||
from flask_login import login_required, login_user, logout_user, current_user
|
||||
from flask_oauthlib.client import OAuthException
|
||||
from werkzeug import exceptions as wz_exceptions
|
||||
|
||||
from pillar.auth import UserClass, subscriptions
|
||||
from pillar.web import system_util
|
||||
from .forms import UserProfileForm
|
||||
@ -192,7 +194,13 @@ def users_edit(user_id):
|
||||
if not current_user.has_role('admin'):
|
||||
return abort(403)
|
||||
api = system_util.pillar_api()
|
||||
user = User.find(user_id, api=api)
|
||||
|
||||
try:
|
||||
user = User.find(user_id, api=api)
|
||||
except sdk_exceptions.ResourceNotFound:
|
||||
log.warning('Non-existing user %r requested.', user_id)
|
||||
raise wz_exceptions.NotFound('Non-existing user %r requested.' % user_id)
|
||||
|
||||
form = UserEditForm()
|
||||
if form.validate_on_submit():
|
||||
def get_groups(roles):
|
||||
|
@ -104,7 +104,20 @@ script(type="text/javascript").
|
||||
var url = '/u/' + userId + '/edit?embed=1';
|
||||
$.get(url, function(dataHtml){
|
||||
$('#search-hit-container').html(dataHtml);
|
||||
});
|
||||
})
|
||||
.fail(function(jqXHR, textStatus, errorThrown) {
|
||||
var $userbox = $(".search-hit.users[data-user-id='" + userId + "']");
|
||||
var $msgbox = $userbox.find('.search-hit-roles');
|
||||
|
||||
if (console) console.log('Error fetching user', userId, '; jqXHR=', jqXHR);
|
||||
$userbox.addClass('alert alert-warning');
|
||||
if (jqXHR.status == 404) {
|
||||
$msgbox.text('This user does not seem to exist.');
|
||||
} else {
|
||||
$msgbox.text('There was an error fetching the user: ' + jqXHR.responseText + '.')
|
||||
}
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
$('body').on('click', '.search-hit', function(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user