fix(usermanager): create User and Group OUs if necessary

This commit is contained in:
Julian Lobbes 2022-11-30 00:19:04 +01:00
parent 0ed0a3f981
commit 519cd26e13
2 changed files with 12 additions and 2 deletions

View File

@ -54,6 +54,4 @@ def create_app(test_config=None):
api.add_resource(webapi.GroupMemberResource, '/api/group/<string:groupname>/member/<string:username>')
api.init_app(app)
# TODO create OUs
return app

View File

@ -33,6 +33,18 @@ def _init_static_images():
@bp.before_app_first_request
def _initialize_ldap_dit():
"""Creates the OUs for users and groups if they do not exist yet."""
conn = ldap.get_connection()
if not ldap.ou_exists(conn, current_app.config['LDAP_USERS_OU']):
ldap.create_ou(conn, current_app.config['LDAP_USERS_OU'])
if not ldap.ou_exists(conn, current_app.config['LDAP_GROUPS_OU']):
ldap.create_ou(conn, current_app.config['LDAP_GROUPS_OU'])
conn.unbind()
@bp.route('/')
def index():
"""Home page view."""