Skip to content

Commit

Permalink
Merge pull request #354 from maykinmedia/fix/948-esuite-zaak-bsn-role…
Browse files Browse the repository at this point in the history
…s-query

[#948] Harden `fetch_roles_for_case_and_bsn()` to work with e-Suite
  • Loading branch information
alextreme authored Dec 1, 2022
2 parents 348165a + f9f61fc commit 98b592e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 45 deletions.
37 changes: 15 additions & 22 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from requests import RequestException
from zds_client import ClientError
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.constants import RolOmschrijving
from zgw_consumers.api_models.constants import RolOmschrijving, RolTypes
from zgw_consumers.api_models.zaken import Resultaat, Rol, Status, Zaak
from zgw_consumers.service import get_paginated_results

Expand Down Expand Up @@ -170,31 +170,24 @@ def fetch_case_roles(


def fetch_roles_for_case_and_bsn(case_url: str, bsn: str) -> List[Rol]:
client = build_client("zaak")

if client is None:
return []
"""
note we do a query on all case_roles and then manually filter our roles from the result,
because e-Suite doesn't support querying on both "zaak" AND "betrokkeneIdentificatie__natuurlijkPersoon__inpBsn"
try:
response = client.list(
"rol",
request_kwargs={
"params": {
"zaak": case_url,
"betrokkeneIdentificatie__natuurlijkPersoon__inpBsn": bsn,
}
},
)
except RequestException as e:
logger.exception("exception while making request", exc_info=e)
return []
except ClientError as e:
logger.exception("exception while making request", exc_info=e)
see Taiga #948
"""
case_roles = fetch_case_roles(case_url)
if not case_roles:
return []

roles = factory(Rol, response["results"])
bsn_roles = []
for role in case_roles:
if role.betrokkene_type == RolTypes.natuurlijk_persoon:
inp_bsn = role.betrokkene_identificatie.get("inp_bsn")
if inp_bsn and inp_bsn == bsn:
bsn_roles.append(role)

return roles
return bsn_roles


def fetch_case_information_objects_for_case_and_info(
Expand Down
40 changes: 27 additions & 13 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,29 @@ def setUpTestData(self):
volgnummer=2,
is_eindstatus=False,
)
self.role = generate_oas_component(
self.user_role = generate_oas_component(
"zrc",
"schemas/Rol",
url=f"{ZAKEN_ROOT}rollen/f33153aa-adnatuurlijk_persoon2c-4a07-ae75-15add5891",
url=f"{ZAKEN_ROOT}rollen/f33153aa-ad2c-4a07-ae75-15add5891",
omschrijvingGeneriek=RolOmschrijving.initiator,
betrokkeneType=RolTypes.natuurlijk_persoon,
betrokkeneIdentificatie={
"geslachtsnaam": "Bazz",
"voorvoegselGeslachtsnaam": "van der",
"inpBsn": "900222086",
"voornamen": "Foo Bar",
"voorvoegselGeslachtsnaam": "van der",
"geslachtsnaam": "Bazz",
},
)
self.not_our_user_role = generate_oas_component(
"zrc",
"schemas/Rol",
url=f"{ZAKEN_ROOT}rollen/aa353aa-ad2c-4a07-ae75-15add5822",
omschrijvingGeneriek=RolOmschrijving.behandelaar,
betrokkeneType=RolTypes.natuurlijk_persoon,
betrokkeneIdentificatie={
"inpBsn": "123456789",
"voornamen": "Somebody",
"geslachtsnaam": "Else",
},
)
self.result = generate_oas_component(
Expand Down Expand Up @@ -253,12 +267,12 @@ def _setUpMocks(self, m):
json=paginated_response([self.status1, self.status2]),
)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&omschrijvingGeneriek={RolOmschrijving.initiator}",
json=paginated_response([self.role]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
json=paginated_response([self.user_role, self.not_our_user_role]),
)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
json=paginated_response([self.role]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&omschrijvingGeneriek={RolOmschrijving.initiator}",
json=paginated_response([self.user_role]),
)
m.get(
f"{ZAKEN_ROOT}resultaten/a44153aa-ad2c-6a07-be75-15add5113",
Expand Down Expand Up @@ -422,9 +436,9 @@ def test_no_access_when_no_roles_are_found_for_user_bsn(self, m):
json=paginated_response([self.status1, self.status2]),
)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
# no roles found
json=paginated_response([]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
# no roles for our user found
json=paginated_response([self.not_our_user_role]),
)
response = self.app.get(
reverse(
Expand Down Expand Up @@ -480,8 +494,8 @@ def test_no_access_when_case_is_confidential(self, m):
mock_service_oas_get(m, CATALOGI_ROOT, "ztc")
m.get(self.zaak_invisible["url"], json=self.zaak_invisible)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak_invisible['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
json=paginated_response([self.role]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak_invisible['url']}",
json=paginated_response([self.user_role, self.not_our_user_role]),
)

response = self.app.get(
Expand Down
43 changes: 33 additions & 10 deletions src/open_inwoner/openzaak/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

import requests_mock
from django_webtest import WebTest
from zgw_consumers.api_models.constants import VertrouwelijkheidsAanduidingen
from zgw_consumers.api_models.constants import (
RolOmschrijving,
RolTypes,
VertrouwelijkheidsAanduidingen,
)
from zgw_consumers.constants import APITypes
from zgw_consumers.test import generate_oas_component, mock_service_oas_get

Expand Down Expand Up @@ -75,11 +79,30 @@ def setUpTestData(self):
beschrijving="",
registratiedatum="2021-01-12",
)
self.role = generate_oas_component(
self.user_role = generate_oas_component(
"zrc",
"schemas/Rol",
url=f"{ZAKEN_ROOT}rollen/f33153aa-ad2c-4a07-ae75-15add5891",
betrokkene_identificatie="foo",
omschrijvingGeneriek=RolOmschrijving.initiator,
betrokkeneType=RolTypes.natuurlijk_persoon,
betrokkeneIdentificatie={
"inpBsn": "900222086",
"voornamen": "Foo Bar",
"voorvoegselGeslachtsnaam": "van der",
"geslachtsnaam": "Bazz",
},
)
self.not_our_user_role = generate_oas_component(
"zrc",
"schemas/Rol",
url=f"{ZAKEN_ROOT}rollen/aa353aa-ad2c-4a07-ae75-15add5822",
omschrijvingGeneriek=RolOmschrijving.behandelaar,
betrokkeneType=RolTypes.natuurlijk_persoon,
betrokkeneIdentificatie={
"inpBsn": "123456789",
"voornamen": "Somebody",
"geslachtsnaam": "Else",
},
)
self.informatie_object_content = "my document content".encode("utf8")
self.informatie_object = generate_oas_component(
Expand Down Expand Up @@ -117,8 +140,8 @@ def _setUpAccessMocks(self, m):
self._setUpOASMocks(m)
m.get(self.zaak["url"], json=self.zaak)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
json=paginated_response([self.role]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
json=paginated_response([self.user_role, self.not_our_user_role]),
)
m.get(
f"{ZAKEN_ROOT}zaakinformatieobjecten?zaak={self.zaak['url']}&informatieobject={self.informatie_object['url']}",
Expand Down Expand Up @@ -225,18 +248,18 @@ def test_no_data_is_retrieved_when_no_related_roles_are_found_for_user_bsn(self,
self._setUpOASMocks(m)
m.get(self.zaak["url"], json=self.zaak)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
# no roles found
json=paginated_response([]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
# no roles for our user found
json=paginated_response([self.not_our_user_role]),
)
self.app.get(self.informatie_object_file.url, user=self.user, status=403)

def test_no_data_is_retrieved_when_no_matching_case_info_object_is_found(self, m):
self._setUpOASMocks(m)
m.get(self.zaak["url"], json=self.zaak)
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}&betrokkeneIdentificatie__natuurlijkPersoon__inpBsn={self.user.bsn}",
json=paginated_response([self.role]),
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
json=paginated_response([self.user_role, self.not_our_user_role]),
)
m.get(self.informatie_object["url"], json=self.informatie_object)
m.get(
Expand Down

0 comments on commit 98b592e

Please sign in to comment.