From 7572736e0faf59acdb5aff603dce983254baf098 Mon Sep 17 00:00:00 2001 From: Julian Lobbes Date: Mon, 21 Nov 2022 15:41:43 +0100 Subject: [PATCH] feat(usermanager): add group list view --- lumi2/templates/usermanager/group_edit.html | 6 +- lumi2/templates/usermanager/group_list.html | 45 +++++++++++++++ lumi2/usermanager.py | 63 +++++++++++++++++---- 3 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 lumi2/templates/usermanager/group_list.html diff --git a/lumi2/templates/usermanager/group_edit.html b/lumi2/templates/usermanager/group_edit.html index 2d4e826..79b4d4f 100644 --- a/lumi2/templates/usermanager/group_edit.html +++ b/lumi2/templates/usermanager/group_edit.html @@ -13,7 +13,7 @@ - + @@ -39,11 +39,11 @@
Other usersOther users
-
+
- + diff --git a/lumi2/templates/usermanager/group_list.html b/lumi2/templates/usermanager/group_list.html new file mode 100644 index 0000000..2834588 --- /dev/null +++ b/lumi2/templates/usermanager/group_list.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} + +{% block content %} +
+

All groups

+
+ +{% if groups %} +
+
{{ groupname }}{{ groupname }}
+ + + + + + + + {% for group in groups | sort %} + + + + + {% endfor %} + +
Group NameMembers
+ {{ group.groupname }} + + {% for user in group.members %} + {% endfor %} +
+
+{% else %} +
+

There are currently no groups.

+
+{% endif %} +{% endblock content %} diff --git a/lumi2/usermanager.py b/lumi2/usermanager.py index c039c92..a8b1e10 100644 --- a/lumi2/usermanager.py +++ b/lumi2/usermanager.py @@ -58,10 +58,10 @@ def user_view(username: str): conn.unbind() abort(404) - user._generate_static_images() conn.unbind() return render_template('usermanager/user_view.html',user=user) + @bp.route("/users/list") def user_list(): """Displays a list of all users.""" @@ -73,9 +73,6 @@ def user_list(): except Exception: abort(500) - for user in users: - user._generate_static_images() - return render_template( 'usermanager/user_list.html', users=users, @@ -238,8 +235,6 @@ def user_update(username: str): conn.unbind() abort(404) - user._generate_static_images() - form = UserUpdateForm(obj=user) if form.validate_on_submit(): if form.email.data: @@ -252,14 +247,11 @@ def user_update(username: str): user.display_name = form.display_name.data if form.password.data: user.password_hash = User.generate_password_hash(form.password.data) - picture_updated = False if form.picture.data and form.picture.data.filename: user.picture = Image.open(form.picture.data, formats=['JPEG']) - picture_updated = True + user._generate_static_images(force=True) ldap.update_user(conn, user) - if picture_updated: - user._generate_static_images(force=True) conn.unbind() flash(f"Information for user '{user.username}' was updated.") return redirect(url_for('usermanager.user_view', username=user.username)) @@ -315,6 +307,57 @@ def user_delete(username: str): ) +@bp.route("/groups/list") +def group_list(): + """Displays a list of all groups.""" + + try: + conn = ldap.get_connection() + groups = ldap.get_groups(conn) + conn.unbind() + except Exception: + abort(500) + + return render_template( + 'usermanager/group_list.html', + groups=groups, + ) + + +@bp.route("/groups/create", methods=("GET", "POST")) +def group_create(): + """Displays a form allowing group creation.""" + + try: + conn = ldap.get_connection() + except Exception: + abort(500) + + conn.unbind() + # TODO implement + abort(404) + + +@bp.route("/groups/view/") +def group_view(groupname: str): + """Displays a form allowing group creation.""" + + try: + conn = ldap.get_connection() + except Exception: + abort(500) + + try: + group = ldap.get_group(conn, groupname) + except ldap.EntryNotFoundException: + conn.unbind() + abort(404) + + conn.unbind() + # TODO implement + abort(404) + + class GroupUpdateForm(FlaskForm): updated_members = HiddenField( 'Group Members',