modify user batch create
This commit is contained in:
parent
8eacdc8db9
commit
cc7ff9d359
2 changed files with 16 additions and 10 deletions
|
@ -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):
|
||||
|
|
|
@ -33,8 +33,10 @@ schema = {
|
|||
}
|
||||
|
||||
schema_multiple = {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": schema
|
||||
"users": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": schema
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue