Skip to content

Commit 935ac02

Browse files
authored
Merge pull request #1626 from maykinmedia/issue/3052-clickthrough-zaak-vraag
[#3052] Fix clickthrough zaak -> vraag
2 parents 5f031e5 + d7c7d44 commit 935ac02

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/open_inwoner/accounts/views/contactmoments.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def get_context_data(self, **kwargs):
202202
service = self.get_service(service_type=KlantenServiceType.OPENKLANT2)
203203

204204
origin = self.request.headers.get("Referer")
205-
question, zaak = service.retrieve_question(
205+
question, zaak_with_api_group = service.retrieve_question(
206206
self.get_fetch_params(service),
207207
question_uuid=kwargs["kcm_uuid"],
208208
user=self.request.user,
@@ -220,16 +220,16 @@ def get_context_data(self, **kwargs):
220220
local_kcm.save()
221221

222222
ctx["question"] = question
223-
ctx["zaak"] = zaak.zaak if zaak else None
223+
ctx["zaak"] = getattr(zaak_with_api_group, "zaak", None)
224224
case_url = (
225225
reverse(
226226
"cases:case_detail",
227227
kwargs={
228-
"object_id": str(zaak.zaak.uuid),
229-
"api_group_id": zaak.api_group.id,
228+
"object_id": str(zaak_with_api_group.zaak.uuid),
229+
"api_group_id": zaak_with_api_group.api_group.id,
230230
},
231231
)
232-
if zaak
232+
if zaak_with_api_group
233233
else None
234234
)
235235
ctx["metrics"] = [
@@ -255,7 +255,7 @@ def get_context_data(self, **kwargs):
255255
"label": _("Terug naar overzicht"),
256256
"url": origin,
257257
}
258-
if zaak:
258+
if zaak_with_api_group:
259259
ctx["destination"] = {
260260
"label": _("Naar aanvraag"),
261261
"url": case_url,

src/open_inwoner/openklant/services.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,6 @@ def retrieve_question(
14651465

14661466
onderwerp_object = onderwerp_objecten[0]
14671467

1468-
zaak_with_api_group = None
1469-
14701468
# fetch zaken for user
14711469
groups = ZGWApiGroupConfig.objects.filter(
14721470
klant_backend=KlantenServiceType.OPENKLANT2.value
@@ -1480,17 +1478,22 @@ def retrieve_question(
14801478
)
14811479
return self._build_question_dto(question_ok2=question, user=user), None
14821480

1483-
# find the unique zaak for the question
1481+
# find the unique zaak + relevant api client for the question
14841482
zaken_for_question = []
1483+
clients = []
14851484
for response in truthy_responses:
14861485
# discard the client for determining the api_group; we only need the zaak
14871486
zaken = response.result
1487+
client = response.client
14881488
zaken_filtered = filter(
14891489
lambda z: z.identificatie
14901490
== onderwerp_object["onderwerpobjectidentificator"]["objectId"],
14911491
zaken,
14921492
)
14931493
zaken_for_question.extend(zaken_filtered)
1494+
clients.append(client)
1495+
1496+
# sanity checks
14941497
if not zaken_for_question:
14951498
logger.info(
14961499
"Could not find zaak corresponding to question %s",
@@ -1503,10 +1506,18 @@ def retrieve_question(
15031506
question.question_kcm_uuid,
15041507
)
15051508
return self._build_question_dto(question_ok2=question, user=user), None
1509+
if len(clients) > 1:
1510+
logger.error("Found one zaak in multiple backends")
1511+
return self._build_question_dto(question_ok2=question, user=user), None
1512+
1513+
group = ZGWApiGroupConfig.objects.resolve_group_from_hints(client=clients[0])
1514+
zaak_with_api_group = ZaakWithApiGroup(
1515+
zaak=zaken_for_question[0], api_group=group
1516+
)
15061517

15071518
return (
15081519
self._build_question_dto(question_ok2=question, user=user),
1509-
zaken_for_question[0],
1520+
zaak_with_api_group,
15101521
)
15111522

15121523
def _build_question_dtos(

0 commit comments

Comments
 (0)