def create(request: CreateRequest): user_id = request.id with translate_errors_context("creating user"): if user_id and User.objects(id=user_id).only("id"): raise errors.bad_request.UserIdExists(id=user_id) user = User(**request.to_struct()) user.save(force_insert=True)
def _ensure_backend_user(user_id: str, company_id: str, user_name: str): given_name, _, family_name = user_name.partition(" ") User( id=user_id, company=company_id, name=user_name, given_name=given_name, family_name=family_name, ).save() return user_id
def ensure_fixed_user(user: FixedUser, company_id: str, log: Logger): if User.objects(id=user.user_id).first(): return data = attr.asdict(user) data["id"] = user.user_id data["email"] = f"{user.user_id}@example.com" data["role"] = Role.user _ensure_auth_user(user_data=data, company_id=company_id, log=log) given_name, _, family_name = user.name.partition(" ") User( id=user.user_id, company=company_id, name=user.name, given_name=given_name, family_name=family_name, ).save()
def add_user(name, passwd): user = User(name, passwd) db.session.add(user) db.session.commit() return