diff --git a/areas/users/user_service.py b/areas/users/user_service.py index d6062ec..882a7ad 100644 --- a/areas/users/user_service.py +++ b/areas/users/user_service.py @@ -98,17 +98,21 @@ class UserService: # for every item in array call Kratos - check if there can be batch create on Kratos # - if yes, what happens with the batch if there is at least one existing email created_users = [] + not_created_users = [] - for user_data in data: + for user_data in data['users']: + user_mail = user_data["email"] + if not user_mail: + return try: - user = UserService.post_user(user) + user = UserService.post_user(user_data) + current_app.logger.info(f"Batch create user: {user_mail}") created_users.append(user) - except Exception: - current_app.logger.error( - "Exception calling Kratos %s\n on creating user %s, %s\n", - Exception, user_data["email"], user_data["name"]) + except Exception as error: + current_app.logger.error(f"Exception calling Kratos: {error} on creating user: {user_mail}") + not_created_users.append(user_mail) - return created_users + return {"created_users": created_users, "not_created_users": not_created_users} @staticmethod def __insertAppRoleToUser(userId, userRes): diff --git a/areas/users/validation.py b/areas/users/validation.py index 08f0113..4131c83 100644 --- a/areas/users/validation.py +++ b/areas/users/validation.py @@ -33,8 +33,10 @@ schema = { } schema_multiple = { - "type": "array", - "items": { - "$ref": schema + "users": { + "type": "array", + "items": { + "$ref": schema + } } }