feat: get user self orgs endpoint
All checks were successful
ci / lint_and_test (push) Successful in 14s
All checks were successful
ci / lint_and_test (push) Successful in 14s
This commit is contained in:
parent
ebcb0362c6
commit
56569f09db
2 changed files with 59 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ from src.user.schemas import (
|
|||
OIDCClaims,
|
||||
UserPostInvitationRequest,
|
||||
UserPostInvitationAcceptRequest,
|
||||
UserGetSelfOrgsResponse,
|
||||
)
|
||||
from src.user.dependencies import (
|
||||
user_model_claims_dependency,
|
||||
|
|
@ -113,6 +114,42 @@ async def delete_user_by_id(
|
|||
db.commit()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/self/orgs",
|
||||
summary="Get all orgs the current user is a member of",
|
||||
status_code=status.HTTP_200_OK,
|
||||
response_model=UserGetSelfOrgsResponse,
|
||||
responses={},
|
||||
)
|
||||
async def get_user_orgs(user_model: user_model_claims_dependency):
|
||||
user_orgs = user_model.organisation_rel
|
||||
response = []
|
||||
for org in user_orgs:
|
||||
response.append(
|
||||
{
|
||||
"organisation_id": org.id,
|
||||
"name": org.name,
|
||||
"status": org.status,
|
||||
"intake_questionnaire": org.intake_questionnaire,
|
||||
"root_user_email": org.root_user_email,
|
||||
"billing_contact": {
|
||||
"id": org.billing_contact_id,
|
||||
"email": org.owner_contact_rel.email,
|
||||
},
|
||||
"owner_contact": {
|
||||
"id": org.owner_contact_id,
|
||||
"email": org.owner_contact_rel.email,
|
||||
},
|
||||
"security_contact": {
|
||||
"id": org.security_contact_id,
|
||||
"email": org.security_contact_rel.email,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
return {"organisations": response}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/invitation",
|
||||
summary="Send an email invitation for a user to join an org",
|
||||
|
|
|
|||
|
|
@ -5,9 +5,27 @@ Pydantic models for the user module
|
|||
from typing import Optional
|
||||
from pydantic import EmailStr
|
||||
|
||||
from src.organisation.constants import Status
|
||||
from src.organisation.schemas import Questionnaire
|
||||
from src.schemas import CustomBaseModel, OrgIDMixin
|
||||
|
||||
|
||||
class ContactModel(CustomBaseModel):
|
||||
id: int
|
||||
email: Optional[EmailStr] = None
|
||||
|
||||
|
||||
class OrgSchema(OrgIDMixin):
|
||||
name: str
|
||||
status: Status
|
||||
root_user_email: EmailStr
|
||||
intake_questionnaire: Questionnaire
|
||||
|
||||
billing_contact: ContactModel
|
||||
owner_contact: ContactModel
|
||||
security_contact: ContactModel
|
||||
|
||||
|
||||
class OIDCClaims(CustomBaseModel):
|
||||
exp: int
|
||||
iat: int
|
||||
|
|
@ -54,3 +72,7 @@ class UserPostInvitationRequest(OrgIDMixin):
|
|||
|
||||
class UserPostInvitationAcceptRequest(CustomBaseModel):
|
||||
jwt: str
|
||||
|
||||
|
||||
class UserGetSelfOrgsResponse(CustomBaseModel):
|
||||
organisations: list[OrgSchema]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue