Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [#2088] Implement Zaken search for eHerkenning users #1030

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions src/open_inwoner/cms/cases/views/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from view_breadcrumbs import BaseBreadcrumbMixin

from open_inwoner.htmx.mixins import RequiresHtmxMixin
from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openzaak.cases import preprocess_data
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.formapi import fetch_open_submissions
from open_inwoner.openzaak.models import OpenZaakConfig
from open_inwoner.openzaak.types import UniformCase
from open_inwoner.openzaak.utils import get_user_fetch_parameters
from open_inwoner.utils.mixins import PaginationMixin
from open_inwoner.utils.views import CommonPageMixin

Expand Down Expand Up @@ -61,20 +61,8 @@ def get_cases(self):
if client is None:
return []

if self.request.user.kvk:
kvk_or_rsin = self.request.user.kvk
config = OpenZaakConfig.get_solo()
if config.fetch_eherkenning_zaken_with_rsin:
kvk_or_rsin = self.request.user.rsin
vestigingsnummer = get_kvk_branch_number(self.request.session)
if vestigingsnummer:
raw_cases = client.fetch_cases_by_kvk_or_rsin(
kvk_or_rsin=kvk_or_rsin, vestigingsnummer=vestigingsnummer
)
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(**get_user_fetch_parameters(self.request))

preprocessed_cases = preprocess_data(raw_cases)
return preprocessed_cases

Expand Down
28 changes: 27 additions & 1 deletion src/open_inwoner/openzaak/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,37 @@


class ZakenClient(APIClient):
def fetch_cases(
self,
user_bsn: Optional[str] = None,
user_kvk_or_rsin: Optional[str] = None,
max_requests: int = 4,
identificatie: Optional[str] = None,
vestigingsnummer: Optional[str] = None,
):
if user_bsn and (user_kvk_or_rsin or vestigingsnummer):
raise ValueError(
"either `user_bsn` or `user_kvk_or_rsin`/`vestigingsnummer` should be supplied, not both"
)

if user_bsn:
Bartvaderkin marked this conversation as resolved.
Show resolved Hide resolved
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,
)
return []

@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
26 changes: 26 additions & 0 deletions src/open_inwoner/openzaak/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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 @@ -142,3 +143,28 @@ def translate_single_status(status_text: str) -> str:
)
except StatusTranslation.DoesNotExist:
return ""


def get_user_fetch_parameters(request) -> dict:
"""
Determine the parameters used to perform ZGW resource fetches
"""
user = request.user

if not user.is_authenticated:
return {}

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}
vestigingsnummer = get_kvk_branch_number(request.session)
if vestigingsnummer:
parameters.update({"vestigingsnummer": vestigingsnummer})
return parameters
return {}
19 changes: 3 additions & 16 deletions src/open_inwoner/pdc/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

from open_inwoner.accounts.models import User
from open_inwoner.configurations.models import SiteConfiguration
from open_inwoner.kvk.branches import get_kvk_branch_number
from open_inwoner.openzaak.api_models import Zaak
from open_inwoner.openzaak.clients import build_client
from open_inwoner.openzaak.models import OpenZaakConfig, ZaakTypeConfig
from open_inwoner.openzaak.models import ZaakTypeConfig
from open_inwoner.openzaak.utils import get_user_fetch_parameters


class ProductQueryset(models.QuerySet):
Expand Down Expand Up @@ -56,20 +56,7 @@ def filter_by_zaken_for_request(self, request):
if client is None:
return self.none()

if request.user.bsn:
cases = client.fetch_cases(request.user.bsn)
elif request.user.kvk:
kvk_or_rsin = request.user.kvk
config = OpenZaakConfig.get_solo()
if config.fetch_eherkenning_zaken_with_rsin:
kvk_or_rsin = request.user.rsin
vestigingsnummer = get_kvk_branch_number(request.session)
if vestigingsnummer:
cases = client.fetch_cases_by_kvk_or_rsin(
kvk_or_rsin=kvk_or_rsin, vestigingsnummer=vestigingsnummer
)
else:
cases = client.fetch_cases_by_kvk_or_rsin(kvk_or_rsin=kvk_or_rsin)
cases = client.fetch_cases(**get_user_fetch_parameters(request))

return self.filter_by_zaken(cases)

Expand Down
6 changes: 3 additions & 3 deletions src/open_inwoner/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

Expand Down Expand Up @@ -62,10 +63,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_user_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
Loading