add some group management

This commit is contained in:
Franzi 2021-12-21 09:27:25 +01:00
parent 602127cbdc
commit 026fbf3c58
Signed by: kunsi
GPG key ID: 12E3D2136B818350
6 changed files with 157 additions and 21 deletions

View file

@ -0,0 +1,38 @@
from functools import wraps
from json import load
from os import environ
from flask import redirect, render_template, session, url_for
from .ldap import get_user
with open(environ["APP_CONFIG"]) as f:
APP_CONFIG = load(f)
def template(ldap, name, **kwargs):
user = None
is_admin = False
if ldap:
user = get_user(ldap, session["username"])
ldap.search(
APP_CONFIG["ldap"]["user_base"],
APP_CONFIG["template"]["group_admin"].format(user["uid"]),
attributes=["uid"],
)
if len(ldap.entries) == 1:
is_admin = True
return render_template(
name,
APP_CONFIG=APP_CONFIG,
CURRENT_USER=user,
USER_IS_ADMIN=is_admin,
**kwargs,
)
class UserNotFoundException(Exception):
pass