Skip to content

Commit

Permalink
✨ [#2088] Implement Zaken search for eHerkenning users
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 15, 2024
1 parent b4d6777 commit faebc1f
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_cases(self):
else:
raw_cases = client.fetch_cases_by_kvk_or_rsin(kvk_or_rsin=kvk_or_rsin)
else:
raw_cases = client.fetch_cases(self.request.user.bsn)
raw_cases = client.fetch_cases_by_bsn(self.request.user.bsn)
preprocessed_cases = preprocess_data(raw_cases)
return preprocessed_cases

Expand Down
22 changes: 21 additions & 1 deletion src/open_inwoner/openzaak/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,31 @@


class ZakenClient(APIClient):
def fetch_cases(
self,
user_bsn=None,
user_kvk_or_rsin=None,
max_requests=4,
identificatie=None,
vestigingsnummer=None,
):
if user_bsn:
return self.fetch_cases_by_bsn(
user_bsn, max_requests=max_requests, identificatie=identificatie
)
elif user_kvk_or_rsin:
return self.fetch_cases_by_kvk_or_rsin(
user_kvk_or_rsin,
max_requests=max_requests,
zaak_identificatie=identificatie,
vestigingsnummer=vestigingsnummer,
)

@cache_result(
"cases:{user_bsn}:{max_requests}:{identificatie}",
timeout=settings.CACHE_ZGW_ZAKEN_TIMEOUT,
)
def fetch_cases(
def fetch_cases_by_bsn(
self,
user_bsn: str,
max_requests: Optional[int] = 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def handle(self, *args, **options):
if not case_uuid:
# if no case_ref is supplied display list of cases and some information about each

cases = zaken_client.fetch_cases(user.bsn)
cases = zaken_client.fetch_cases_by_bsn(user.bsn)
for case in cases:
case_type = catalogi_client.fetch_single_case_type(case.zaaktype)
case.zaaktype = case_type
Expand Down
24 changes: 24 additions & 0 deletions src/open_inwoner/openzaak/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from zgw_consumers.api_models.constants import RolTypes, VertrouwelijkheidsAanduidingen

from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openzaak.api_models import InformatieObject, Rol, Zaak, ZaakType

from .models import (
Expand Down Expand Up @@ -143,3 +144,26 @@ def translate_single_status(status_text: str) -> str:
)
except StatusTranslation.DoesNotExist:
return ""


def get_fetch_parameters(request, use_vestigingsnummer: bool = True) -> dict:
"""
Determine the parameters used to perform ZGW resource fetches
"""
user = request.user

if user.bsn:
return {"user_bsn": user.bsn}
elif user.kvk:
kvk_or_rsin = user.kvk
config = OpenZaakConfig.get_solo()
if config.fetch_eherkenning_zaken_with_rsin:
kvk_or_rsin = user.rsin

parameters = {"user_kvk_or_rsin": kvk_or_rsin}
if use_vestigingsnummer:
vestigingsnummer = get_kvk_branch_number(request.session)
if vestigingsnummer:
parameters.update({"vestigingsnummer": vestigingsnummer})
return parameters
return {}
2 changes: 1 addition & 1 deletion src/open_inwoner/pdc/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def filter_by_zaken_for_request(self, request):
return self.none()

if request.user.bsn:
cases = client.fetch_cases(request.user.bsn)
cases = client.fetch_cases_by_bsn(request.user.bsn)
elif request.user.kvk:
kvk_or_rsin = request.user.kvk
config = OpenZaakConfig.get_solo()
Expand Down
7 changes: 4 additions & 3 deletions src/open_inwoner/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.utils import get_fetch_parameters
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import CommonPageMixin, LoginMaybeRequiredMixin, LogMixin

Expand Down Expand Up @@ -62,10 +64,9 @@ def search(self, form):
self.log_user_action(user, _("search query: {query}").format(query=query))

# Check if the query exactly matches with a case that belongs to the user
# TODO should be implemented for KVK as well
if hasattr(self.request.user, "bsn"):
if search_params := get_fetch_parameters(self.request):
if client := build_client("zaak"):
cases = client.fetch_cases(self.request.user.bsn, identificatie=query)
cases = client.fetch_cases(**search_params, identificatie=query)
if cases and len(cases) == 1:
return HttpResponseRedirect(
reverse(
Expand Down

0 comments on commit faebc1f

Please sign in to comment.