feat(usermanager): add group deletion view

This commit is contained in:
Julian Lobbes 2022-11-30 18:37:19 +01:00
parent 182c17ebac
commit 8d73839de7
10 changed files with 75 additions and 17 deletions

View File

@ -72,7 +72,7 @@ class UserEntry {
this.buttonElement.addClass("btn-danger");
this.buttonElement.empty();
this.buttonElement.html(
'<i class="bi-box-arrow-right"></i> Remove from group'
'<i class="bi-person-fill-dash"></i> Remove'
);
}
@ -81,7 +81,7 @@ class UserEntry {
this.buttonElement.addClass("btn-success");
this.buttonElement.empty();
this.buttonElement.html(
'<i class="bi-box-arrow-right"></i> Add to group'
'<i class="bi-person-fill-add"></i> Add'
);
}
}

View File

@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block content %}
<div class="row justify-content-sm-center">
<div class="col-sm text-center align-self-center m-2">
<p><b>Are you sure</b> you want to <b class="text-danger">delete</b> the group '{{ groupname }}'?</p>
<p class="text-muted">No Users will be deleted.</p>
</div>
</div>
<div class="row justify-content-sm-center">
<div class="col-sm text-center align-self-center m-2">
<a class="btn btn-secondary"
href="{{ url_for('usermanager.group_update', groupname=groupname) }}"
role="button">No, take me back!</a>
</div>
<div class="col-sm text-center align-self-center m-2">
<form method="post">
<input class="btn btn-danger" type="submit" value="Yes, delete this group.">
</form>
</div>
</div>
{% endblock content %}

View File

@ -3,19 +3,25 @@
{% block content %}
<div class="row">
<div class="col">
<h1>Editing group: {{ groupname }}</h1>
<h1 class="text-center">Editing group: {{ groupname }}</h1>
</div>
</div>
<div class="text-center border-bottom pb-1 mb-1">
<a class="btn btn-outline-danger"
href="{{ url_for('usermanager.group_delete', groupname=groupname) }}"
role="button"
><i class="bi-x-square"></i> Delete Group</a>
</div>
<div class="row">
<div class="col-sm border border-primary rounded m-2">
<table class="table table-hover align-middle" id="tableMembers">
<thead>
<tr>
<th scope="col" colspan="3">Username</th>
<th scope="col" colspan="3" class="text-center">{{ groupname }}</th>
</tr>
</thead>
<tbody>
{% for user in members %}
{% for user in members|sort %}
<tr class="userEntry text-center" id="{{ user.username }}">
<th scope="row">
<img src="{{ user.get_thumbnail_url() }}"
@ -29,7 +35,7 @@
</td>
<td>
<button type="button" class="toggleMembershipButton btn btn-danger">
<i class="bi-box-arrow-right"></i> Remove from group
<i class="bi-person-fill-dash"></i> Remove
</button>
</td>
</tr>
@ -41,11 +47,11 @@
<table class="table table-hover align-middle" id="tableNonMembers">
<thead>
<tr>
<th scope="col" colspan="3">Username</th>
<th scope="col" colspan="3" class="text-center">Other Users</th>
</tr>
</thead>
<tbody>
{% for user in non_members %}
{% for user in non_members|sort %}
<tr class="userEntry text-center" id="{{ user.username }}">
<th scope="row">
<img src="{{ user.get_thumbnail_url() }}"
@ -59,7 +65,7 @@
</td>
<td>
<button type="button" class="toggleMembershipButton btn btn-success">
<i class="bi-box-arrow-in-right"></i> Add to group
<i class="bi-person-fill-add"></i> Add
</button>
</td>
</tr>

View File

@ -4,7 +4,7 @@
<div class="text-center border-bottom mb-1">
<h1>All groups</h1>
</div>
<div class="text-end border-bottom pb-1 mb-1">
<div class="text-center border-bottom pb-1 mb-1">
<a class="btn btn-primary"
href="{{ url_for('usermanager.group_create') }}"
role="button"

View File

@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% block content %}
<h1>Welcome to LUMI 2</h1>
<h1 class="text-center">Welcome to LUMI 2</h1>
<div class="row justify-content-md-center">
<img src="{{ url_for('static', filename='images/base/toolbox.svg') }}"
alt="Picture of a toolbox."

View File

@ -24,11 +24,11 @@
<div class="col-sm text-center align-self-center m-2">
<a class="btn btn-secondary"
href="{{ url_for('usermanager.user_view', username=username) }}"
role="button">No, take me back</a>
role="button">No, take me back!</a>
</div>
<div class="col-sm text-center align-self-center m-2">
<form method="post">
<input class="btn btn-danger" type="submit" value="Yes, delete this user">
<input class="btn btn-danger" type="submit" value="Yes, delete this user.">
</form>
</div>
</div>

View File

@ -3,7 +3,7 @@
{% block content %}
<div class="row">
<div class="col">
<h1>{{ heading }}</h1>
<h1 class="text-center">{{ heading }}</h1>
</div>
</div>
<form method="post" enctype="multipart/form-data">

View File

@ -4,7 +4,7 @@
<div class="text-center border-bottom mb-1">
<h1>All users</h1>
</div>
<div class="text-end border-bottom pb-1 mb-1">
<div class="text-center border-bottom pb-1 mb-1">
<a class="btn btn-primary"
href="{{ url_for('usermanager.user_create') }}"
role="button"

View File

@ -19,10 +19,10 @@
<div class="col-sm-auto vstack gap-1 align-self-center m-2">
<a class="btn btn-primary"
href="{{ url_for('usermanager.user_update', username=user.username) }}"
role="button">Edit</a>
role="button"><i class="bi-person-gear"></i> Edit</a>
<a class="btn btn-danger"
href="{{ url_for('usermanager.user_delete', username=user.username) }}"
role="button">Delete</a>
role="button"><i class="bi-person-slash"></i> Delete</a>
</div>
</div>
{% endblock content %}

View File

@ -392,3 +392,33 @@ def group_update(groupname: str):
members=members,
non_members=non_members,
)
@bp.route("/groups/delete/<string:groupname>", methods=("GET", "POST"))
def group_delete(groupname: str):
"""Deletion view for a specific Group.
Provides a form prompting the confirmation of the specified group.
"""
try:
conn = ldap.get_connection()
except Exception:
abort(500)
try:
group = ldap.get_group(conn, groupname)
except ldap.EntryNotFoundException:
conn.unbind()
abort(404)
if request.method == 'POST':
ldap.delete_group(conn, group.groupname)
conn.unbind()
flash(f"The group '{group.groupname}' was deleted.")
return redirect(url_for('usermanager.group_list'))
return render_template(
'usermanager/group_delete.html',
groupname=group.groupname,
)