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
|
# 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
|
# - if yes, what happens with the batch if there is at least one existing email
|
||||||
created_users = []
|
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:
|
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)
|
created_users.append(user)
|
||||||
except Exception:
|
except Exception as error:
|
||||||
current_app.logger.error(
|
current_app.logger.error(f"Exception calling Kratos: {error} on creating user: {user_mail}")
|
||||||
"Exception calling Kratos %s\n on creating user %s, %s\n",
|
not_created_users.append(user_mail)
|
||||||
Exception, user_data["email"], user_data["name"])
|
|
||||||
|
|
||||||
return created_users
|
return {"created_users": created_users, "not_created_users": not_created_users}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __insertAppRoleToUser(userId, userRes):
|
def __insertAppRoleToUser(userId, userRes):
|
||||||
|
|
|
@ -33,8 +33,10 @@ schema = {
|
||||||
}
|
}
|
||||||
|
|
||||||
schema_multiple = {
|
schema_multiple = {
|
||||||
"type": "array",
|
"users": {
|
||||||
"items": {
|
"type": "array",
|
||||||
"$ref": schema
|
"items": {
|
||||||
|
"$ref": schema
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue