From a50ba403fc3040f141c552d74ee92b8494f3d179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 17 Feb 2023 20:40:27 +0100 Subject: [PATCH] feat(ldap) fix sync from ldap --- flaschengeist/plugins/auth_ldap/cli.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/flaschengeist/plugins/auth_ldap/cli.py b/flaschengeist/plugins/auth_ldap/cli.py index d306d21..e3d772f 100644 --- a/flaschengeist/plugins/auth_ldap/cli.py +++ b/flaschengeist/plugins/auth_ldap/cli.py @@ -1,6 +1,7 @@ import click from flask import current_app from flask.cli import with_appcontext +from werkzeug.exceptions import NotFound @click.command(no_args_is_help=True) @@ -13,8 +14,10 @@ def ldap(ctx, sync): from flaschengeist.controller import userController from flaschengeist.plugins.auth_ldap import AuthLDAP from ldap3 import SUBTREE + from flaschengeist.models import User + from flaschengeist.database import db - auth_ldap: AuthLDAP = current_app.config.get("FG_AUTH_BACKEND") + auth_ldap: AuthLDAP = current_app.config.get("FG_PLUGINS").get("auth_ldap") if auth_ldap is None or not isinstance(auth_ldap, AuthLDAP): ctx.fail("auth_ldap plugin not found or not enabled!") conn = auth_ldap.ldap.connection @@ -24,4 +27,9 @@ def ldap(ctx, sync): ldap_users_response = conn.response for ldap_user in ldap_users_response: uid = ldap_user["attributes"]["uid"][0] - userController.find_user(uid) + try: + user = userController.get_user(uid) + except NotFound: + user = User(userid=uid) + db.session.add(user) + userController.update_user(user, auth_ldap)