From a088943015a96075dac2d8838a2c90e7008a185c Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Tue, 22 Oct 2024 18:17:29 +0000 Subject: [PATCH] refactor(models): default agency card templates further simplify template requirements for flows rename agency card templates into standard naming pattern: {prefix}--{agency.slug}--agency-card.html where {prefix} is e.g. eligibility/start or enrollment/success --- benefits/core/admin.py | 8 +- ...sitagency_enrollmentflow_optionalfields.py | 40 ++++++- benefits/core/migrations/local_fixtures.json | 6 +- benefits/core/models.py | 57 ++++++++-- ...-idcardcheck--start--mst-agency-card.html} | 0 ...dcardcheck--start--sbmtd-agency-card.html} | 0 ... => selection-label--mst-agency-card.html} | 0 ...> selection-label--sbmtd-agency-card.html} | 0 ...-card.html => start--mst-agency-card.html} | 2 +- ...ass.html => start--sbmtd-agency-card.html} | 2 +- ....html => unverified--mst-agency-card.html} | 0 ...tml => unverified--sbmtd-agency-card.html} | 0 ...ard.html => success--mst-agency-card.html} | 0 ...s.html => success--sbmtd-agency-card.html} | 0 tests/pytest/conftest.py | 2 + tests/pytest/core/test_models.py | 102 +++++++++++++----- 16 files changed, 166 insertions(+), 53 deletions(-) rename benefits/eligibility/templates/eligibility/includes/{media-item--idcardcheck--start--mst-courtesy-card.html => media-item--idcardcheck--start--mst-agency-card.html} (100%) rename benefits/eligibility/templates/eligibility/includes/{media-item--idcardcheck--start--sbmtd-mobility-pass.html => media-item--idcardcheck--start--sbmtd-agency-card.html} (100%) rename benefits/eligibility/templates/eligibility/includes/{selection-label--mst-courtesy-card.html => selection-label--mst-agency-card.html} (100%) rename benefits/eligibility/templates/eligibility/includes/{selection-label--sbmtd-mobility-pass.html => selection-label--sbmtd-agency-card.html} (100%) rename benefits/eligibility/templates/eligibility/{start--mst-courtesy-card.html => start--mst-agency-card.html} (96%) rename benefits/eligibility/templates/eligibility/{start--sbmtd-mobility-pass.html => start--sbmtd-agency-card.html} (95%) rename benefits/eligibility/templates/eligibility/{unverified--mst-courtesy-card.html => unverified--mst-agency-card.html} (100%) rename benefits/eligibility/templates/eligibility/{unverified--sbmtd-mobility-pass.html => unverified--sbmtd-agency-card.html} (100%) rename benefits/enrollment/templates/enrollment/{success--mst-courtesy-card.html => success--mst-agency-card.html} (100%) rename benefits/enrollment/templates/enrollment/{success--sbmtd-mobility-pass.html => success--sbmtd-agency-card.html} (100%) diff --git a/benefits/core/admin.py b/benefits/core/admin.py index 7daa1f9659..ab874a846e 100644 --- a/benefits/core/admin.py +++ b/benefits/core/admin.py @@ -65,14 +65,14 @@ def get_readonly_fields(self, request, obj=None): return [ "claims_provider", "eligibility_api_url", - "eligibility_start_template", - "eligibility_unverified_template", + "eligibility_start_template_override", + "eligibility_unverified_template_override", "help_template", - "selection_label_template", + "selection_label_template_override", "claims_scheme_override", "enrollment_index_template", "reenrollment_error_template", - "enrollment_success_template", + "enrollment_success_template_override", ] else: return super().get_readonly_fields(request, obj) diff --git a/benefits/core/migrations/0030_transitagency_enrollmentflow_optionalfields.py b/benefits/core/migrations/0030_transitagency_enrollmentflow_optionalfields.py index 18ecd60962..c6ae656d5a 100644 --- a/benefits/core/migrations/0030_transitagency_enrollmentflow_optionalfields.py +++ b/benefits/core/migrations/0030_transitagency_enrollmentflow_optionalfields.py @@ -90,6 +90,16 @@ class Migration(migrations.Migration): old_name="eligibility_start_template", new_name="eligibility_start_template_override", ), + migrations.RenameField( + model_name="enrollmentflow", + old_name="eligibility_unverified_template", + new_name="eligibility_unverified_template_override", + ), + migrations.RenameField( + model_name="enrollmentflow", + old_name="enrollment_index_template", + new_name="enrollment_index_template_override", + ), migrations.RenameField( model_name="enrollmentflow", old_name="enrollment_success_template", @@ -121,6 +131,16 @@ class Migration(migrations.Migration): blank=True, help_text="A human readable label, used as the display text in Admin.", null=True ), ), + migrations.AlterField( + model_name="enrollmentflow", + name="selection_label_template_override", + field=models.TextField( + blank=True, + default=None, + help_text="Override the default template that defines the end-user UI for selecting this flow among other options.", # noqa: E501 + null=True, + ), + ), migrations.AlterField( model_name="enrollmentflow", name="eligibility_start_template_override", @@ -133,21 +153,31 @@ class Migration(migrations.Migration): ), migrations.AlterField( model_name="enrollmentflow", - name="enrollment_success_template_override", + name="eligibility_unverified_template_override", field=models.TextField( blank=True, - default="enrollment/success.html", - help_text="Override the default template for a successful enrollment associated with the enrollment flow", + default=None, + help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501 null=True, ), ), migrations.AlterField( model_name="enrollmentflow", - name="selection_label_template_override", + name="enrollment_index_template_override", + field=models.TextField( + blank=True, + default=None, + help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)", # noqa: E501 + null=True, + ), + ), + migrations.AlterField( + model_name="enrollmentflow", + name="enrollment_success_template_override", field=models.TextField( blank=True, default=None, - help_text="Override the default template that defines the end-user UI for selecting this flow among other options.", # noqa + help_text="Override the default template for a successful enrollment associated with the enrollment flow", null=True, ), ), diff --git a/benefits/core/migrations/local_fixtures.json b/benefits/core/migrations/local_fixtures.json index eea0847f33..ccbe1217ff 100644 --- a/benefits/core/migrations/local_fixtures.json +++ b/benefits/core/migrations/local_fixtures.json @@ -107,8 +107,6 @@ "system_name": "agency_card", "label": "Agency Card", "group_id": "group123", - "enrollment_index_template": "enrollment/index--agency-card.html", - "enrollment_success_template_override": "enrollment/success--cst-agency-card.html", "display_order": 4, "eligibility_api_url": "http://server:8000/verify", "eligibility_api_auth_header": "X-Server-API-Key", @@ -117,10 +115,7 @@ "eligibility_api_jwe_cek_enc": "A256CBC-HS512", "eligibility_api_jwe_encryption_alg": "RSA-OAEP", "eligibility_api_jws_signing_alg": "RS256", - "selection_label_template_override": "eligibility/includes/selection-label--cst-agency-card.html", - "eligibility_start_template_override": "eligibility/start--cst-agency-card.html", "eligibility_form_class": "benefits.eligibility.forms.CSTAgencyCard", - "eligibility_unverified_template": "eligibility/unverified--cst-agency-card.html", "help_template": "core/includes/help--cst-agency-card.html", "supported_enrollment_methods": ["digital", "in_person"], "transit_agency": 1 @@ -136,6 +131,7 @@ "supports_expiration": "True", "expiration_days": 5, "expiration_reenrollment_days": 3, + "enrollment_index_template_override": "enrollment/index--calfresh.html", "reenrollment_error_template": "enrollment/reenrollment-error--calfresh.html", "display_order": 2, "claims_provider": 1, diff --git a/benefits/core/models.py b/benefits/core/models.py index f97c9089f8..1d9182071f 100644 --- a/benefits/core/models.py +++ b/benefits/core/models.py @@ -378,9 +378,11 @@ class EnrollmentFlow(models.Model): blank=True, help_text="The fully qualified Python path of a form class used by this flow, e.g. benefits.eligibility.forms.FormClass", # noqa: E501 ) - eligibility_unverified_template = models.TextField( - default="eligibility/unverified.html", - help_text="Path to a Django template that defines the page when a user fails eligibility verification for this flow.", + eligibility_unverified_template_override = models.TextField( + help_text="Override the default template that defines the page when a user fails eligibility verification for this flow.", # noqa: E501 + blank=True, + null=True, + default=None, ) help_template = models.TextField( null=True, @@ -404,9 +406,11 @@ class EnrollmentFlow(models.Model): blank=True, help_text="If the enrollment supports expiration, number of days preceding the expiration date during which a user can re-enroll in the eligibilty", # noqa: E501 ) - enrollment_index_template = models.TextField( - default="enrollment/index.html", - help_text="Template for the Eligibility Confirmation page (which is the index of the enrollment Django app)", + enrollment_index_template_override = models.TextField( + help_text="Override the default template for the Eligibility Confirmation page (the index of the enrollment app)", + null=True, + blank=True, + default=None, ) reenrollment_error_template = models.TextField( null=True, blank=True, help_text="Template for a re-enrollment error associated with the enrollment flow" @@ -432,6 +436,13 @@ class Meta: def __str__(self): return self.label + @property + def agency_card_name(self): + if self.uses_claims_verification: + return "" + else: + return f"{self.transit_agency.slug}-agency-card" + @property def eligibility_api_auth_key(self): if self.eligibility_api_auth_key_secret_name is not None: @@ -446,11 +457,27 @@ def eligibility_api_public_key_data(self): @property def selection_label_template(self): - return self.selection_label_template_override or f"eligibility/includes/selection-label--{self.system_name}.html" + prefix = "eligibility/includes/selection-label" + if self.uses_claims_verification: + return self.selection_label_template_override or f"{prefix}--{self.system_name}.html" + else: + return self.selection_label_template_override or f"{prefix}--{self.agency_card_name}.html" @property def eligibility_start_template(self): - return self.eligibility_start_template_override or f"eligibility/start--{self.system_name}.html" + prefix = "eligibility/start" + if self.uses_claims_verification: + return self.eligibility_start_template_override or f"{prefix}--{self.system_name}.html" + else: + return self.eligibility_start_template_override or f"{prefix}--{self.agency_card_name}.html" + + @property + def eligibility_unverified_template(self): + prefix = "eligibility/unverified" + if self.uses_claims_verification: + return self.eligibility_unverified_template_override or f"{prefix}.html" + else: + return self.eligibility_unverified_template_override or f"{prefix}--{self.agency_card_name}.html" @property def uses_claims_verification(self): @@ -468,9 +495,21 @@ def eligibility_verifier(self): else: return self.eligibility_api_url + @property + def enrollment_index_template(self): + prefix = "enrollment/index" + if self.uses_claims_verification: + return self.enrollment_index_template_override or f"{prefix}.html" + else: + return self.enrollment_index_template_override or f"{prefix}--agency-card.html" + @property def enrollment_success_template(self): - return self.enrollment_success_template_override or f"enrollment/success--{self.transit_agency.slug}.html" + prefix = "enrollment/success" + if self.uses_claims_verification: + return self.enrollment_success_template_override or f"{prefix}--{self.transit_agency.slug}.html" + else: + return self.enrollment_success_template_override or f"{prefix}--{self.agency_card_name}.html" def eligibility_form_instance(self, *args, **kwargs): """Return an instance of this flow's EligibilityForm, or None.""" diff --git a/benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--mst-courtesy-card.html b/benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--mst-agency-card.html similarity index 100% rename from benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--mst-courtesy-card.html rename to benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--mst-agency-card.html diff --git a/benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--sbmtd-mobility-pass.html b/benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--sbmtd-agency-card.html similarity index 100% rename from benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--sbmtd-mobility-pass.html rename to benefits/eligibility/templates/eligibility/includes/media-item--idcardcheck--start--sbmtd-agency-card.html diff --git a/benefits/eligibility/templates/eligibility/includes/selection-label--mst-courtesy-card.html b/benefits/eligibility/templates/eligibility/includes/selection-label--mst-agency-card.html similarity index 100% rename from benefits/eligibility/templates/eligibility/includes/selection-label--mst-courtesy-card.html rename to benefits/eligibility/templates/eligibility/includes/selection-label--mst-agency-card.html diff --git a/benefits/eligibility/templates/eligibility/includes/selection-label--sbmtd-mobility-pass.html b/benefits/eligibility/templates/eligibility/includes/selection-label--sbmtd-agency-card.html similarity index 100% rename from benefits/eligibility/templates/eligibility/includes/selection-label--sbmtd-mobility-pass.html rename to benefits/eligibility/templates/eligibility/includes/selection-label--sbmtd-agency-card.html diff --git a/benefits/eligibility/templates/eligibility/start--mst-courtesy-card.html b/benefits/eligibility/templates/eligibility/start--mst-agency-card.html similarity index 96% rename from benefits/eligibility/templates/eligibility/start--mst-courtesy-card.html rename to benefits/eligibility/templates/eligibility/start--mst-agency-card.html index 1cf94ef9e1..5ddfb88b6a 100644 --- a/benefits/eligibility/templates/eligibility/start--mst-courtesy-card.html +++ b/benefits/eligibility/templates/eligibility/start--mst-agency-card.html @@ -12,7 +12,7 @@

{% translate "You selected a Courtesy Card transit benefit." %}

{% endblock headline %} {% block media-item %} - {% include "eligibility/includes/media-item--idcardcheck--start--mst-courtesy-card.html" %} + {% include "eligibility/includes/media-item--idcardcheck--start--mst-agency-card.html" %} {% endblock media-item %} {% block call-to-action %} diff --git a/benefits/eligibility/templates/eligibility/start--sbmtd-mobility-pass.html b/benefits/eligibility/templates/eligibility/start--sbmtd-agency-card.html similarity index 95% rename from benefits/eligibility/templates/eligibility/start--sbmtd-mobility-pass.html rename to benefits/eligibility/templates/eligibility/start--sbmtd-agency-card.html index 0fe01b9e0e..75af35f45d 100644 --- a/benefits/eligibility/templates/eligibility/start--sbmtd-mobility-pass.html +++ b/benefits/eligibility/templates/eligibility/start--sbmtd-agency-card.html @@ -12,7 +12,7 @@

{% translate "You selected a Reduced Fare Mobility ID transit benefit." %}