def create_non_existing_user(connection_id: str, username: UserId) -> None: if user_exists(username): return # User exists. Nothing to do... users = load_users(lock=True) users[username] = new_user_template(connection_id) save_users(users) # Call the sync function for this new user connection = get_connection(connection_id) try: if connection is None: raise MKUserError(None, _("Invalid user connection: %s") % connection_id) connection.do_sync(add_to_changelog=False, only_username=username, load_users_func=load_users, save_users_func=save_users) except MKLDAPException as e: show_exception(connection_id, _("Error during sync"), e, debug=config.debug) except Exception as e: show_exception(connection_id, _("Error during sync"), e)
def create_non_existing_user(connection_id: str, username: UserId) -> None: # Since user_exists also looks into the htpasswd and treats all users that can be found there as # "existing users", we don't care about partially known users here and don't create them ad-hoc. # The load_users() method will handle this kind of users (TODO: Consolidate this!). # Which makes this function basically relevant for users that authenticate using an LDAP # connection and do not exist yet. if user_exists(username): return # User exists. Nothing to do... users = load_users(lock=True) users[username] = new_user_template(connection_id) save_users(users) # Call the sync function for this new user connection = get_connection(connection_id) try: if connection is None: raise MKUserError(None, _("Invalid user connection: %s") % connection_id) connection.do_sync(add_to_changelog=False, only_username=username, load_users_func=load_users, save_users_func=save_users) except MKLDAPException as e: show_exception(connection_id, _("Error during sync"), e, debug=config.debug) except Exception as e: show_exception(connection_id, _("Error during sync"), e)