From bcdef91dd0beadbf56e10582ce62d0b78df9563f Mon Sep 17 00:00:00 2001 From: luxferre Date: Thu, 11 Jun 2026 14:14:31 +0100 Subject: [PATCH] feat: user invite response models --- src/user/router.py | 20 ++++++++++++++++++-- src/user/schemas.py | 12 +++++++++++- test/test_user.py | 10 +++++++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/user/router.py b/src/user/router.py index 9a3b78a..fe9dbef 100644 --- a/src/user/router.py +++ b/src/user/router.py @@ -17,6 +17,8 @@ from src.user.schemas import ( UserPostInvitationRequest, UserPostInvitationAcceptRequest, UserGetSelfOrgsResponse, + UserPostInvitationResponse, + UserPostInvitationAcceptResponse, ) from src.user.dependencies import ( user_model_claims_dependency, @@ -153,6 +155,7 @@ async def get_user_orgs(user_model: user_model_claims_dependency): "/invitation", summary="Send an email invitation for a user to join an org", status_code=status.HTTP_200_OK, + response_model=UserPostInvitationResponse, ) async def invitation( background_tasks: BackgroundTasks, @@ -167,13 +170,19 @@ async def invitation( send_invitation, org_id=org_id, org_name=org_name, user_email=user_email ) - return "Invitation sent" + response = { + "organisation": org_model, + "invited_email": user_email, + } + + return response @router.post( "/invitation/accept", summary="Accept email invitation to join an org", status_code=status.HTTP_200_OK, + response_model=UserPostInvitationAcceptResponse, ) async def accept_invitation( db: db_dependency, @@ -189,6 +198,13 @@ async def accept_invitation( raise OrgNotFoundException() org_model.user_rel.append(user_model) + db.flush() + + response = { + "organisation": org_model, + "user": user_model, + } + db.commit() - return "Invitation accepted" + return response diff --git a/src/user/schemas.py b/src/user/schemas.py index ddff869..65ab530 100644 --- a/src/user/schemas.py +++ b/src/user/schemas.py @@ -6,7 +6,7 @@ from typing import Optional from pydantic import EmailStr from src.organisation.schemas import OrgSchema -from src.schemas import CustomBaseModel, OrgIDMixin +from src.schemas import CustomBaseModel, OrgIDMixin, OrgSummary, UserSummary class OIDCClaims(CustomBaseModel): @@ -60,3 +60,13 @@ class UserPostInvitationAcceptRequest(CustomBaseModel): class UserGetSelfOrgsResponse(CustomBaseModel): organisations: list[OrgSchema] + + +class UserPostInvitationResponse(CustomBaseModel): + organisation: OrgSummary + invited_email: EmailStr + + +class UserPostInvitationAcceptResponse(CustomBaseModel): + organisation: OrgSummary + user: UserSummary diff --git a/test/test_user.py b/test/test_user.py index 148ecae..ab87aef 100644 --- a/test/test_user.py +++ b/test/test_user.py @@ -70,7 +70,15 @@ async def test_post_user_invitation_success(default_client: AsyncClient): resp = await default_client.post("/user/invitation", json=body) assert resp.status_code == 200 - assert resp.json() == "Invitation sent" + data = resp.json() + assert "organisation" in data + assert isinstance(data["organisation"], dict) + assert data["organisation"]["id"] == 1 + assert data["organisation"]["name"] == "Test Org" + + assert "invited_email" in data + assert isinstance(data["invited_email"], str) + assert data["invited_email"] == "admin@test.com" @pytest.mark.parametrize(