Skip to content

Commit

Permalink
[#1829] Make call-to-action url + text configurable per statustype
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Nov 1, 2023
1 parent fc58ad9 commit 490b79e
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 27 deletions.
38 changes: 37 additions & 1 deletion src/open_inwoner/cms/cases/tests/test_contactform.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ def setUp(self):
vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar,
indicatieInternOfExtern="extern",
)
#
# statuses
#
self.status_new = generate_oas_component(
"zrc",
"schemas/Status",
url=f"{ZAKEN_ROOT}statussen/3da81560-c7fc-476a-ad13-beu760sle929",
zaak=self.zaak["url"],
statustype=f"{CATALOGI_ROOT}statustypen/e3798107-ab27-4c3c-977d-777yu878km09",
datumStatusGezet="2021-01-12",
statustoelichting="",
)
self.status_finish = generate_oas_component(
"zrc",
"schemas/Status",
Expand All @@ -122,14 +134,32 @@ def setUp(self):
datumStatusGezet="2021-03-12",
statustoelichting="",
)
#
# status types
#
self.status_type_new = generate_oas_component(
"ztc",
"schemas/StatusType",
url=self.status_new["statustype"],
zaaktype=self.zaaktype["url"],
catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a",
omschrijving="Initial request",
omschrijvingGeneriek="Nieuw",
statustekst="",
volgnummer=1,
isEindstatus=False,
)
self.status_type_finish = generate_oas_component(
"ztc",
"schemas/StatusType",
url=self.status_finish["statustype"],
zaaktype=self.zaaktype["url"],
catalogus=f"{CATALOGI_ROOT}catalogussen/1b643db-81bb-d71bd5a2317a",
omschrijving="Finish",
omschrijvingGeneriek="some content",
omschrijvingGeneriek="Afgehandeld",
statustekst="",
volgnummer=1,
isEindstatus=True,
)
self.result = generate_oas_component(
"zrc",
Expand Down Expand Up @@ -181,6 +211,12 @@ def _setUpMocks(self, m):
]:
self.matchers.append(m.get(resource["url"], json=resource))

# mock `fetch_status_types_no_cache`
m.get(
f"{CATALOGI_ROOT}statustypen?zaaktype={self.zaak['zaaktype']}",
json=paginated_response([self.status_type_new, self.status_type_finish]),
)

self.matchers += [
m.get(
f"{ZAKEN_ROOT}rollen?zaak={self.zaak['url']}",
Expand Down
32 changes: 28 additions & 4 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ def get_context_data(self, **kwargs):
"status_indicator_text",
None,
),
"call_to_action_url": getattr(
statustype_config_mapping.get(end_statustype.url),
"call_to_action_url",
None,
),
"call_to_action_text": getattr(
statustype_config_mapping.get(end_statustype.url),
"call_to_action_text",
None,
),
}

context["case"] = {
Expand Down Expand Up @@ -204,6 +214,7 @@ def get_context_data(self, **kwargs):
)
else:
context["case"] = None

return context

def get_upload_info_context(self, case: Zaak):
Expand Down Expand Up @@ -258,21 +269,23 @@ def get_upload_info_context(self, case: Zaak):
),
}

def get_result_display(self, case: Zaak) -> str:
@staticmethod
def get_result_display(case: Zaak) -> str:
if case.resultaat:
result = fetch_single_result(case.resultaat)
if result:
return result.toelichting
return None

def get_initiator_display(self, case: Zaak) -> str:
@staticmethod
def get_initiator_display(case: Zaak) -> str:
roles = fetch_case_roles(case.url, RolOmschrijving.initiator)
if not roles:
return ""
return ", ".join([get_role_name_display(r) for r in roles])

@staticmethod
def get_statuses_data(
self,
statuses: List[Status],
lookup: TranslationLookup,
statustype_config_mapping: Optional[dict] = None,
Expand All @@ -293,11 +306,22 @@ def get_statuses_data(
"status_indicator_text",
None,
),
"call_to_action_url": getattr(
statustype_config_mapping.get(s.statustype.url),
"call_to_action_url",
None,
),
"call_to_action_text": getattr(
statustype_config_mapping.get(s.statustype.url),
"call_to_action_text",
None,
),
}
for s in statuses
]

def get_case_document_files(self, case: Zaak) -> List[SimpleFile]:
@staticmethod
def get_case_document_files(case: Zaak) -> List[SimpleFile]:
case_info_objects = fetch_case_information_objects(case.url)

# get the information objects for the case objects
Expand Down
3 changes: 3 additions & 0 deletions src/open_inwoner/openzaak/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ class ZaakTypeStatusTypeConfigInline(admin.TabularInline):
"zaaktype_uuids",
"status_indicator",
"status_indicator_text",
"show_document_uploads",
"document_upload_description",
"call_to_action_url",
"call_to_action_text",
]
readonly_fields = [
"statustekst",
Expand Down
20 changes: 0 additions & 20 deletions src/open_inwoner/openzaak/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,6 @@ def fetch_single_status_type(status_type_url: str) -> Optional[StatusType]:
return status_type


@cache_result(
"resultaat_type:{resultaat_type_url}", timeout=settings.CACHE_ZGW_CATALOGI_TIMEOUT
)
def fetch_single_resultaat_type(resultaat_type_url: str) -> Optional[ResultaatType]:
client = build_client("catalogi")

if client is None:
return

try:
response = client.retrieve("resultaattype", url=resultaat_type_url)
except (RequestException, ClientError) as e:
logger.exception("exception while making request", exc_info=e)
return

resultaat_type = factory(ResultaatType, response)

return resultaat_type


# not cached because only used by tools,
# and because caching (stale) listings can break lookups
def fetch_zaaktypes_no_cache() -> List[ZaakType]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 3.2.20 on 2023-10-31 11:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("openzaak", "0027_zaaktype_resultaattype_config"),
]

operations = [
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="call_to_action_text",
field=models.CharField(
blank=True,
default="",
help_text="The text displayed on the call-to-action button",
max_length=48,
verbose_name="Call to action text",
),
),
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="call_to_action_url",
field=models.URLField(
blank=True,
default="",
help_text="The url the user will be sent to by clicking on the call-to-action button",
verbose_name="Call to action url",
),
),
migrations.AddField(
model_name="zaaktypestatustypeconfig",
name="show_document_uploads",
field=models.BooleanField(
default=True,
help_text="Wheter document uploads are to be shown",
verbose_name="Show document uploads",
),
),
]
20 changes: 20 additions & 0 deletions src/open_inwoner/openzaak/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,26 @@ class ZaakTypeStatusTypeConfig(models.Model):
"Description that will be shown above the document upload widget in a case detail page"
),
)
show_document_uploads = models.BooleanField(
default=True,
verbose_name=_("Show document uploads"),
help_text=_("Wheter document uploads are to be shown"),
)
call_to_action_url = models.URLField(
blank=True,
default="",
verbose_name=_("Call to action url"),
help_text=_(
"The url the user will be sent to by clicking on the call-to-action button"
),
)
call_to_action_text = models.CharField(
max_length=48,
blank=True,
default="",
verbose_name=_("Call to action text"),
help_text=_("The text displayed on the call-to-action button"),
)

class Meta:
verbose_name = _("Zaaktype Statustype Configuration")
Expand Down
1 change: 1 addition & 0 deletions src/open_inwoner/openzaak/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class ZaakTypeStatusTypeConfigFactory(factory.django.DjangoModelFactory):
zaaktype_config = factory.SubFactory(ZaakTypeConfigFactory)
statustype_url = factory.Faker("url")
omschrijving = factory.Faker("pystr", max_chars=80)
# call_to_action_url = statustype_url

class Meta:
model = ZaakTypeStatusTypeConfig
Expand Down
12 changes: 12 additions & 0 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
statustype_url=self.status_type_finish["url"],
status_indicator=StatusIndicators.success,
status_indicator_text="bar",
call_to_action_url="https://www.example.com",
call_to_action_text="Click me",
)

self._setUpMocks(m)
Expand Down Expand Up @@ -406,12 +408,16 @@ def test_status_is_retrieved_when_user_logged_in_via_digid(self, m):
"label": "Initial request",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
"call_to_action_text": "",
},
{
"date": datetime.datetime(2021, 3, 12),
"label": "Finish",
"status_indicator": "success",
"status_indicator_text": "bar",
"call_to_action_url": "https://www.example.com",
"call_to_action_text": "Click me",
},
],
# only one visible information object
Expand Down Expand Up @@ -440,6 +446,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
statustype_url=self.status_type_finish["url"],
status_indicator=StatusIndicators.success,
status_indicator_text="bar",
call_to_action_url="https://www.example.com",
call_to_action_text="Click me",
)

self._setUpMocks(m, use_eindstatus=False)
Expand All @@ -464,6 +472,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"label": "Finish",
"status_indicator": "success",
"status_indicator_text": "bar",
"call_to_action_url": "https://www.example.com",
"call_to_action_text": "Click me",
},
"description": "Coffee zaaktype",
"statuses": [
Expand All @@ -472,6 +482,8 @@ def test_pass_endstatus_type_data_if_endstatus_not_reached(self, m):
"label": "Initial request",
"status_indicator": "warning",
"status_indicator_text": "foo",
"call_to_action_url": "",
"call_to_action_text": "",
},
],
# only one visible information object
Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/openzaak/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def setUpTestData(cls):
statustype_url=cls.status_type1["url"],
status_indicator=StatusIndicators.warning,
status_indicator_text="U moet documenten toevoegen",
call_to_action_url="https://example.com",
call_to_action_text="yolo",
)
# open
cls.zaak1 = generate_oas_component(
Expand Down
8 changes: 6 additions & 2 deletions src/open_inwoner/templates/pages/cases/status_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ <h3 class="status-list__notification-h3"><a href="#" class="link link-toggle lin
{% button href="#form_upload" text=_("Scroll naar document uploaden") title=_("Ga direct naar document upload sectie.") primary=True icon="arrow_downward" icon_position="after" %}
{% endif %}
{# IF there is a CTA button in the final status, show this #}
{# {% button href=call_to_action_url text=_("Bekijk uw voltooide aanvraag") title=_("Open de bijlage") primary=True icon="arrow_forward" icon_position="after" %} #}
{# ENDIF #}
{% with button_url=case.end_statustype_data.call_to_action_url %}
{% if button_url %}
{% translate case.end_statustype_data.call_to_action_text as button_text %}
{% button href=button_url text=button_text title=_("Open de bijlage") primary=True icon="arrow_forward" icon_position="after" %}
{% endif %}
{% endwith %}
</p>
</div>
</div>
Expand Down

0 comments on commit 490b79e

Please sign in to comment.