diff --git a/lumi2/static/js/group_edit.js b/lumi2/static/js/group_edit.js index 88ddddc..a80ffdb 100644 --- a/lumi2/static/js/group_edit.js +++ b/lumi2/static/js/group_edit.js @@ -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([ + '' + ].join('')); +} + function getUserEntries() { let userEntries = []; diff --git a/lumi2/templates/base.html b/lumi2/templates/base.html index 406e032..3c6f8fa 100644 --- a/lumi2/templates/base.html +++ b/lumi2/templates/base.html @@ -57,7 +57,10 @@ {% with messages = get_flashed_messages() %} {% if messages %} {% for message in messages %} -
{{ message }}
+ {% endfor %} {% endif %} {% endwith %} diff --git a/lumi2/webapi.py b/lumi2/webapi.py index ce41ead..8c0e50e 100644 --- a/lumi2/webapi.py +++ b/lumi2/webapi.py @@ -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()