fix(usermanager): error messages display
This commit is contained in:
parent
18a2bf89e9
commit
0ed0a3f981
@ -26,11 +26,10 @@ class UserEntry {
|
||||
$(this.userEntry.buttonElement).click(() => this.userEntry.onClickJoin());
|
||||
$(this.userEntry.rowElement).prependTo($("#tableNonMembers").find("tbody"));
|
||||
this.userEntry.setButtonAppearanceJoinGroup();
|
||||
// TODO check status code!
|
||||
}).fail(function(xhr, status, errorThrown) {
|
||||
console.log(`Error: ${errorThrown}`);
|
||||
console.log(`Status: ${status}`);
|
||||
alert("Sorry, there was a problem retrieving information from the server.");
|
||||
showErrorMessage(xhr.responseJSON['message']);
|
||||
this.userEntry.setButtonAppearanceLeaveGroup();
|
||||
});
|
||||
}
|
||||
@ -50,12 +49,11 @@ class UserEntry {
|
||||
$(this.userEntry.buttonElement).click(() => this.userEntry.onClickLeave());
|
||||
$(this.userEntry.rowElement).prependTo($("#tableMembers").find("tbody"));
|
||||
this.userEntry.setButtonAppearanceLeaveGroup();
|
||||
// TODO check status code!
|
||||
}).fail(function(xhr, status, errorThrown) {
|
||||
console.log(`Error: ${errorThrown}`);
|
||||
console.log(`Status: ${status}`);
|
||||
alert("Sorry, there was a problem retrieving information from the server.");
|
||||
this.userEntry.setButtonAppearanceLeaveGroup();
|
||||
showErrorMessage(xhr.responseJSON['message']);
|
||||
this.userEntry.setButtonAppearanceJoinGroup();
|
||||
});
|
||||
}
|
||||
|
||||
@ -88,6 +86,15 @@ class UserEntry {
|
||||
}
|
||||
}
|
||||
|
||||
function showErrorMessage(message) {
|
||||
$("nav").after([
|
||||
'<div class="alert alert-danger alert-dismissible" role="alert">',
|
||||
`<div>${message}</div>`,
|
||||
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>',
|
||||
'</div>'
|
||||
].join(''));
|
||||
}
|
||||
|
||||
function getUserEntries() {
|
||||
let userEntries = [];
|
||||
|
||||
|
@ -57,7 +57,10 @@
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-primary mt-3">{{ message }}</div>
|
||||
<div class="alert alert-primary alert-dismissible" role="alert">
|
||||
<div>{{ message }}</div>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
@ -283,6 +283,14 @@ class GroupMemberResource(Resource):
|
||||
conn.unbind()
|
||||
return {"message": f"User '{username}' is not a member of the Group '{group.groupname}'."}, 400
|
||||
|
||||
if len(group.members) == 1:
|
||||
conn.unbind()
|
||||
return {
|
||||
"message": f"Cannot remove user '{username}', because they are currently the only member " \
|
||||
f"of '{group.groupname}'. Empty groups are not permitted in LDAP, so either " \
|
||||
f"delete the group or add another user before removing '{username}'."
|
||||
}, 400
|
||||
|
||||
group.members.remove(user)
|
||||
ldap.update_group(conn, group)
|
||||
conn.unbind()
|
||||
|
Loading…
Reference in New Issue
Block a user