From 8a9f03ee0b0bfb0c53ee81da302c9083b153d46c Mon Sep 17 00:00:00 2001 From: luxferre Date: Wed, 3 Jun 2026 09:38:54 +0100 Subject: [PATCH] feat: get users includes org info --- src/organisation/router.py | 4 ++-- src/organisation/schemas.py | 9 +++++++-- test/test_organisation.py | 4 ++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/organisation/router.py b/src/organisation/router.py index 6c9ab13..9cbfbda 100644 --- a/src/organisation/router.py +++ b/src/organisation/router.py @@ -185,7 +185,7 @@ async def get_users(org_model: org_model_root_claim_query_dependency): """ Returns a list of the email addresses of all users of the organisation. """ - return {"users": [user.email for user in org_model.user_rel]} + return {"users": [user.email for user in org_model.user_rel], "organisation": org_model} @router.post("/user", @@ -313,7 +313,7 @@ async def get_contact(org_model: org_model_root_claim_query_dependency, contact_ address = ContactAddress.model_validate(contact_model) contact_response = ContactModel.model_construct(**contact_model.__dict__, address=address) - return {"contact": contact_response} + return {"contact": contact_response, "organisation": org_model} @router.patch("/contact", diff --git a/src/organisation/schemas.py b/src/organisation/schemas.py index f562d46..3ecfe26 100644 --- a/src/organisation/schemas.py +++ b/src/organisation/schemas.py @@ -17,13 +17,17 @@ from src.user.schemas import UserIDMixin from src.organisation.constants import Status, ContactType +class OrgIDMixin(CustomBaseModel): + organisation_id: int = Field(gt=0) + class Questionnaire(CustomBaseModel): question_one: Optional[str] = None question_two: Optional[str] = None question_three: Optional[str] = None -class OrgIDMixin(CustomBaseModel): - organisation_id: int = Field(gt=0) +class OrgSchema(CustomBaseModel): + id: int + name: str class OrgPostOrgRequest(CustomBaseModel): @@ -84,6 +88,7 @@ class OrgPatchRootResponse(CustomBaseModel): class OrgGetUserResponse(CustomBaseModel): users: list[str] + organisation: OrgSchema class OrgGetGroupResponse(CustomBaseModel): groups: list[str] diff --git a/test/test_organisation.py b/test/test_organisation.py index 6b4648c..6dfaa21 100644 --- a/test/test_organisation.py +++ b/test/test_organisation.py @@ -159,6 +159,10 @@ async def test_get_org_users_success(client: AsyncClient): assert len(data["users"]) == 1 assert data["users"][0] == "admin@test.com" + assert "organisation" in data + assert data["organisation"]["name"] == "Test Org" + assert data["organisation"]["id"] == 1 + @pytest.mark.parametrize( "query, expected_status",