Create a new account in the database. Args: payload (dict): The payload to create the user Returns: UserDB: instance of user
(payload: dict)
| 1054 | |
| 1055 | |
| 1056 | async def create_accounts(payload: dict) -> UserDB: |
| 1057 | """Create a new account in the database. |
| 1058 | |
| 1059 | Args: |
| 1060 | payload (dict): The payload to create the user |
| 1061 | |
| 1062 | Returns: |
| 1063 | UserDB: instance of user |
| 1064 | """ |
| 1065 | |
| 1066 | # pop required fields for organization & workspace creation |
| 1067 | organization_id = payload.pop("organization_id") |
| 1068 | |
| 1069 | # create user |
| 1070 | user_info = {**payload, "username": payload["email"].split("@")[0]} |
| 1071 | user_db = await user_service.create_new_user(payload=user_info) |
| 1072 | |
| 1073 | # only update organization to have user_db as its "owner" if it does not yet have one |
| 1074 | # ---> updating the organization only happens in the first-user scenario |
| 1075 | # where the first-user becomes the organization/workspace owner. |
| 1076 | try: |
| 1077 | await get_organization_owner(organization_id=organization_id) |
| 1078 | except (NoResultFound, ValueError): |
| 1079 | await update_organization( |
| 1080 | organization_id=organization_id, values_to_update={"owner": str(user_db.id)} |
| 1081 | ) |
| 1082 | |
| 1083 | # get project belonging to organization |
| 1084 | project_db = await get_project_by_organization_id(organization_id=organization_id) |
| 1085 | |
| 1086 | # update user invitation in the case the user was invited |
| 1087 | invitation = await get_project_invitation_by_email( |
| 1088 | project_id=str(project_db.id), email=payload["email"] |
| 1089 | ) |
| 1090 | if invitation is not None: |
| 1091 | await update_invitation( |
| 1092 | invitation_id=str(invitation.id), |
| 1093 | values_to_update={"user_id": str(user_db.id), "used": True}, |
| 1094 | ) |
| 1095 | |
| 1096 | return user_db |
| 1097 | |
| 1098 | |
| 1099 | async def create_organization(name: str): |
no test coverage detected