feat: user invite response models
All checks were successful
ci / lint_and_test (push) Successful in 13s
All checks were successful
ci / lint_and_test (push) Successful in 13s
This commit is contained in:
parent
8925280f96
commit
bcdef91dd0
3 changed files with 38 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue