feat: get org response mirrors get user orgs structure
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
939abaefe9
commit
3b82025abb
5 changed files with 52 additions and 46 deletions
|
|
@ -92,17 +92,26 @@ async def get_org_by_id(org_model: org_model_root_claim_query_dependency):
|
||||||
Returns organisation details including key member email addresses
|
Returns organisation details including key member email addresses
|
||||||
"""
|
"""
|
||||||
response = {
|
response = {
|
||||||
"id": org_model.id,
|
"organisation_id": org_model.id,
|
||||||
"name": org_model.name,
|
"name": org_model.name,
|
||||||
"status": org_model.status,
|
"status": org_model.status,
|
||||||
"owner_contact": org_model.owner_contact_rel.email,
|
|
||||||
"billing_contact": org_model.billing_contact_rel.email,
|
|
||||||
"security_contact": org_model.security_contact_rel.email,
|
|
||||||
"root_user": org_model.root_user_email,
|
|
||||||
"intake_questionnaire": org_model.intake_questionnaire,
|
"intake_questionnaire": org_model.intake_questionnaire,
|
||||||
|
"root_user_email": org_model.root_user_email,
|
||||||
|
"billing_contact": {
|
||||||
|
"id": org_model.billing_contact_id,
|
||||||
|
"email": org_model.billing_contact_rel.email,
|
||||||
|
},
|
||||||
|
"owner_contact": {
|
||||||
|
"id": org_model.owner_contact_id,
|
||||||
|
"email": org_model.owner_contact_rel.email,
|
||||||
|
},
|
||||||
|
"security_contact": {
|
||||||
|
"id": org_model.security_contact_id,
|
||||||
|
"email": org_model.security_contact_rel.email,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return response
|
return {"organisations": [response]}
|
||||||
|
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,27 @@ class Questionnaire(CustomBaseModel):
|
||||||
question_three: Optional[str] = None
|
question_three: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
class OrgSchema(CustomBaseModel):
|
class OrgSummary(CustomBaseModel):
|
||||||
id: int
|
id: int
|
||||||
name: str
|
name: str
|
||||||
|
|
||||||
|
|
||||||
|
class ContactSummary(CustomBaseModel):
|
||||||
|
id: int
|
||||||
|
email: Optional[EmailStr] = None
|
||||||
|
|
||||||
|
|
||||||
|
class OrgSchema(OrgIDMixin):
|
||||||
|
name: str
|
||||||
|
status: Status
|
||||||
|
root_user_email: EmailStr
|
||||||
|
intake_questionnaire: Optional[Questionnaire] = None
|
||||||
|
|
||||||
|
billing_contact: ContactSummary
|
||||||
|
owner_contact: ContactSummary
|
||||||
|
security_contact: ContactSummary
|
||||||
|
|
||||||
|
|
||||||
class OrgPostOrgRequest(CustomBaseModel):
|
class OrgPostOrgRequest(CustomBaseModel):
|
||||||
name: str
|
name: str
|
||||||
intake_questionnaire: Optional[Questionnaire] = None
|
intake_questionnaire: Optional[Questionnaire] = None
|
||||||
|
|
@ -93,7 +109,7 @@ class OrgPatchRootResponse(CustomBaseModel):
|
||||||
|
|
||||||
class OrgGetUserResponse(CustomBaseModel):
|
class OrgGetUserResponse(CustomBaseModel):
|
||||||
users: list[dict[str, str | int]]
|
users: list[dict[str, str | int]]
|
||||||
organisation: OrgSchema
|
organisation: OrgSummary
|
||||||
|
|
||||||
|
|
||||||
class OrgGetGroupResponse(CustomBaseModel):
|
class OrgGetGroupResponse(CustomBaseModel):
|
||||||
|
|
@ -104,22 +120,15 @@ class OrgGetContactResponse(CustomBaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True, extra="ignore")
|
model_config = ConfigDict(from_attributes=True, extra="ignore")
|
||||||
|
|
||||||
contact: ContactModel
|
contact: ContactModel
|
||||||
organisation: OrgSchema
|
organisation: OrgSummary
|
||||||
|
|
||||||
|
|
||||||
class OrgPatchContactResponse(CustomBaseModel):
|
class OrgPatchContactResponse(CustomBaseModel):
|
||||||
model_config = ConfigDict(from_attributes=True, extra="ignore")
|
model_config = ConfigDict(from_attributes=True, extra="ignore")
|
||||||
|
|
||||||
contact: ContactModel
|
contact: ContactModel
|
||||||
organisation: OrgSchema
|
organisation: OrgSummary
|
||||||
|
|
||||||
|
|
||||||
class OrgGetOrgResponse(CustomBaseModel):
|
class OrgGetOrgResponse(CustomBaseModel):
|
||||||
id: int
|
organisations: list[OrgSchema]
|
||||||
name: str
|
|
||||||
status: Status
|
|
||||||
root_user: Optional[str] = None
|
|
||||||
owner_contact: Optional[str] = None
|
|
||||||
billing_contact: Optional[str] = None
|
|
||||||
security_contact: Optional[str] = None
|
|
||||||
intake_questionnaire: Optional[Questionnaire] = None
|
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,10 @@ Pydantic models for the user module
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from pydantic import EmailStr
|
from pydantic import EmailStr
|
||||||
|
|
||||||
from src.organisation.constants import Status
|
from src.organisation.schemas import OrgSchema
|
||||||
from src.organisation.schemas import Questionnaire
|
|
||||||
from src.schemas import CustomBaseModel, OrgIDMixin
|
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: Optional[Questionnaire] = None
|
|
||||||
|
|
||||||
billing_contact: ContactModel
|
|
||||||
owner_contact: ContactModel
|
|
||||||
security_contact: ContactModel
|
|
||||||
|
|
||||||
|
|
||||||
class OIDCClaims(CustomBaseModel):
|
class OIDCClaims(CustomBaseModel):
|
||||||
exp: int
|
exp: int
|
||||||
iat: int
|
iat: int
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,4 @@ async def test_get_org_auth_root_su(default_client: AsyncClient, db_session):
|
||||||
resp = await default_client.get("/org?org_id=2")
|
resp = await default_client.get("/org?org_id=2")
|
||||||
assert resp.status_code != 422
|
assert resp.status_code != 422
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert resp.json()["name"] == "Test Org Two"
|
assert resp.json()["organisations"][0]["name"] == "Test Org Two"
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,20 @@ async def test_get_org_success(default_client: AsyncClient):
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert data["id"] == 1
|
|
||||||
assert data["name"] == "Test Org"
|
org = data["organisations"][0]
|
||||||
assert data["status"] == "approved"
|
|
||||||
assert data["root_user"] == "admin@test.com"
|
assert isinstance(org, dict)
|
||||||
assert data["billing_contact"] == "billing@test.org"
|
assert org["organisation_id"] == 1
|
||||||
assert data["owner_contact"] == "owner@test.org"
|
assert org["name"] == "Test Org"
|
||||||
assert data["security_contact"] == "security@test.org"
|
assert org["status"] == "approved"
|
||||||
assert "intake_questionnaire" in data
|
assert org["root_user_email"] == "admin@test.com"
|
||||||
assert isinstance(data["intake_questionnaire"], dict)
|
assert "intake_questionnaire" in org
|
||||||
|
assert isinstance(org["intake_questionnaire"], dict)
|
||||||
|
|
||||||
|
assert org["billing_contact"]["email"] == "billing@test.org"
|
||||||
|
assert org["owner_contact"]["email"] == "owner@test.org"
|
||||||
|
assert org["security_contact"]["email"] == "security@test.org"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue