From 20cd7ce12143f92d925918e9bbd519220eb34d2d Mon Sep 17 00:00:00 2001 From: Paul Schilling Date: Mon, 21 Oct 2024 09:50:39 +0200 Subject: [PATCH] [#2823] Filter contactmomenten on Mijn Vragen based on kanaal --- src/open_inwoner/cms/cases/views/status.py | 11 +++++ .../openzaak/tests/test_case_detail.py | 48 +++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/open_inwoner/cms/cases/views/status.py b/src/open_inwoner/cms/cases/views/status.py index 90cd53ed76..df22c10b07 100644 --- a/src/open_inwoner/cms/cases/views/status.py +++ b/src/open_inwoner/cms/cases/views/status.py @@ -20,6 +20,7 @@ from django.views.generic import FormView, TemplateView from django_htmx.http import HttpResponseClientRedirect +from glom import glom from mail_editor.helpers import find_template from view_breadcrumbs import BaseBreadcrumbMixin from zgw_consumers.api_models.constants import RolOmschrijving @@ -163,6 +164,7 @@ def get_context_data(self, **kwargs): self.store_statustype_mapping(self.case.zaaktype.identificatie) self.store_resulttype_mapping(self.case.zaaktype.identificatie) + # questions/E-suite contactmomenten objectcontactmomenten = [] if contactmoment_client := build_contactmomenten_client(): objectcontactmomenten = ( @@ -183,6 +185,15 @@ def get_context_data(self, **kwargs): question, kcm_answer_mapping ) + # filter questions + openklant_config = OpenKlantConfig.get_solo() + if exclude_range := openklant_config.exclude_contactmoment_kanalen: + questions = [ + item + for item in questions + if glom(item, "kanaal") not in exclude_range + ] + statustypen = [] catalogi_client = api_group.catalogi_client statustypen = catalogi_client.fetch_status_types_no_cache( diff --git a/src/open_inwoner/openzaak/tests/test_case_detail.py b/src/open_inwoner/openzaak/tests/test_case_detail.py index 006339054b..3cf791657e 100644 --- a/src/open_inwoner/openzaak/tests/test_case_detail.py +++ b/src/open_inwoner/openzaak/tests/test_case_detail.py @@ -532,6 +532,19 @@ def setUp(self): antwoord="no", onderwerp="e_suite_subject_code", ) + self.contactmoment_balie = generate_oas_component_cached( + "cmc", + "schemas/Contactmoment", + url=f"{CONTACTMOMENTEN_ROOT}contactmoment/aaaaaaaa-aaaa-aaaa-aaaa-cccccccccccc", + bronorganisatie="123456789", + identificatie="AB123", + registratiedatum="2024-09-27T03:39:28+00:00", + type="SomeType", + kanaal="Balie", + status=ContactMomentStatus.afgehandeld, + antwoord="no", + onderwerp="e_suite_subject_code", + ) self.objectcontactmoment_old = generate_oas_component_cached( "cmc", "schemas/Objectcontactmoment", @@ -548,6 +561,14 @@ def setUp(self): object_type="zaak", contactmoment=self.contactmoment_new["url"], ) + self.objectcontactmoment_balie = generate_oas_component_cached( + "cmc", + "schemas/Objectcontactmoment", + url=f"{CONTACTMOMENTEN_ROOT}objectcontactmomenten/bb51784c-fa2c-4f65-b24e-7179b615efac", + object=self.zaak["url"], + object_type="zaak", + contactmoment=self.contactmoment_balie["url"], + ) self.objectcontactmoment_eherkenning = generate_oas_component_cached( "cmc", "schemas/Objectcontactmoment", @@ -625,8 +646,10 @@ def _setUpMocks(self, m, use_eindstatus=True): self.status_type_finish, self.contactmoment_old, self.contactmoment_new, + self.contactmoment_balie, self.objectcontactmoment_old, self.objectcontactmoment_new, + self.objectcontactmoment_balie, ]: m.get(resource["url"], json=resource) @@ -707,7 +730,11 @@ def _setUpMocks(self, m, use_eindstatus=True): m.get( f"{CONTACTMOMENTEN_ROOT}objectcontactmomenten?object={self.zaak['url']}", json=paginated_response( - [self.objectcontactmoment_old, self.objectcontactmoment_new] + [ + self.objectcontactmoment_old, + self.objectcontactmoment_new, + self.objectcontactmoment_balie, + ] ), ) @@ -719,7 +746,11 @@ def _setUpMocks(self, m, use_eindstatus=True): m.get( f"{CONTACTMOMENTEN_ROOT}objectcontactmomenten?object={self.zaak['url']}", json=paginated_response( - [self.objectcontactmoment_old, self.objectcontactmoment_new] + [ + self.objectcontactmoment_old, + self.objectcontactmoment_new, + self.objectcontactmoment_balie, + ] ), ) @@ -870,6 +901,9 @@ def test_status_is_retrieved_when_user_logged_in_via_digid( status_new_obj.statustype = factory(StatusType, self.status_type_new) status_finish_obj.statustype = factory(StatusType, self.status_type_finish) + self.openklant_config.exclude_contactmoment_kanalen = ["Balie"] + self.openklant_config.save() + response = self.app.get(self.case_detail_url, user=self.user) case = response.context.get("case") @@ -1049,6 +1083,7 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m): "new_docs": False, "questions": [ make_contactmoment(self.contactmoment_new), + make_contactmoment(self.contactmoment_balie), make_contactmoment(self.contactmoment_old), ], }, @@ -1058,7 +1093,7 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m): doc = PyQuery(response.text) links = doc.find(".contactmomenten__link") - self.assertEqual(len(links), 2) + self.assertEqual(len(links), 3) self.assertEqual( links[0].attrib["href"], reverse( @@ -1068,6 +1103,13 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m): ) self.assertEqual( links[1].attrib["href"], + reverse( + "cases:kcm_redirect", + kwargs={"uuid": uuid_from_url(self.contactmoment_balie["url"])}, + ), + ) + self.assertEqual( + links[2].attrib["href"], reverse( "cases:kcm_redirect", kwargs={"uuid": uuid_from_url(self.contactmoment_old["url"])},