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

Refactor: move EligibilityType fields to EnrollmentFlow #2299

Merged
merged 5 commits into from
Aug 16, 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
22 changes: 3 additions & 19 deletions benefits/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,6 @@ def get_readonly_fields(self, request, obj=None):
return super().get_readonly_fields(request, obj)


@admin.register(models.EligibilityType)
class EligibilityTypeAdmin(admin.ModelAdmin): # pragma: no cover
def get_exclude(self, request, obj=None):
if not request.user.is_superuser:
return []
else:
return super().get_exclude(request, obj)

def get_readonly_fields(self, request, obj=None):
if not request.user.is_superuser:
return [
"enrollment_index_template",
"reenrollment_error_template",
"enrollment_success_template",
]
else:
return super().get_readonly_fields(request, obj)


@admin.register(models.EnrollmentFlow)
class SortableEnrollmentFlowAdmin(SortableAdminMixin, admin.ModelAdmin): # pragma: no cover
def get_exclude(self, request, obj=None):
Expand All @@ -86,6 +67,9 @@ def get_readonly_fields(self, request, obj=None):
"help_template",
"selection_label_template",
"claims_scheme_override",
"enrollment_index_template",
"reenrollment_error_template",
"enrollment_success_template",
]
else:
return super().get_readonly_fields(request, obj)
Expand Down
6 changes: 2 additions & 4 deletions benefits/core/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import requests

from benefits import VERSION
from benefits.core.models import EligibilityType
from . import session


Expand Down Expand Up @@ -46,9 +45,8 @@ def __init__(self, request, event_type, **kwargs):
agency = session.agency(request)
agency_name = agency.long_name if agency else None
flow = session.flow(request)
verifier_name = flow.name if flow else None
eligibility_types = session.eligibility(request)
eligibility_types = EligibilityType.get_names(eligibility_types) if eligibility_types else None
verifier_name = flow.system_name if flow else None
eligibility_types = [flow.system_name] if flow else None

self.update_event_properties(
path=request.path,
Expand Down
4 changes: 2 additions & 2 deletions benefits/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ def debug(request):

def enrollment(request):
"""Context processor adds enrollment information to request context."""
eligibility = session.eligibility(request)
flow = session.flow(request)
expiry = session.enrollment_expiry(request)
reenrollment = session.enrollment_reenrollment(request)

data = {
"expires": expiry,
"reenrollment": reenrollment,
"supports_expiration": eligibility.supports_expiration if eligibility else False,
"supports_expiration": flow.supports_expiration if flow else False,
}

return {"enrollment": data}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Generated by Django 5.0.6 on 2024-08-14 16:14

from django.db import migrations, models


def migrate_data(apps, schema_editor):
EnrollmentFlow = apps.get_model("core", "EnrollmentFlow")

for flow in EnrollmentFlow.objects.all():
if flow.eligibility_type is not None:
flow.name = flow.eligibility_type.name
flow.label = flow.eligibility_type.label
flow.group_id = flow.eligibility_type.group_id
flow.supports_expiration = flow.eligibility_type.supports_expiration
flow.expiration_days = flow.eligibility_type.expiration_days
flow.expiration_reenrollment_days = flow.eligibility_type.expiration_reenrollment_days
flow.enrollment_index_template = flow.eligibility_type.enrollment_index_template
flow.enrollment_error_template = flow.eligibility_type.reenrollment_error_template
flow.enrollment_success_template = flow.eligibility_type.enrollment_success_template
flow.save()


class Migration(migrations.Migration):

dependencies = [
("core", "0021_rename_eligibilityverifier_enrollmentflow"),
]

operations = [
migrations.AddField(
model_name="enrollmentflow",
name="enrollment_index_template",
field=models.TextField(
default="enrollment/index.html",
help_text="Template for the Eligibility Confirmation page (which is the index of the enrollment Django app)",
),
),
migrations.AddField(
model_name="enrollmentflow",
name="enrollment_success_template",
field=models.TextField(
default="enrollment/success.html",
help_text="Template for a successful enrollment associated with the enrollment flow",
),
),
migrations.AddField(
model_name="enrollmentflow",
name="expiration_days",
field=models.PositiveSmallIntegerField(
blank=True,
null=True,
help_text="If the enrollment supports expiration, number of days before the eligibility expires",
),
),
migrations.AddField(
model_name="enrollmentflow",
name="expiration_reenrollment_days",
field=models.PositiveSmallIntegerField(
blank=True,
null=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
),
),
migrations.AddField(
model_name="enrollmentflow",
name="group_id",
field=models.TextField(null=True, help_text="Reference to the TransitProcessor group for user enrollment"),
),
migrations.AddField(
model_name="enrollmentflow",
name="label",
field=models.TextField(
null=True, help_text="A human readable label, not shown to end-users. Used as the display text in Admin."
),
),
migrations.AddField(
model_name="enrollmentflow",
name="reenrollment_error_template",
field=models.TextField(
blank=True, null=True, help_text="Template for a re-enrollment error associated with the enrollment flow"
),
),
migrations.AddField(
model_name="enrollmentflow",
name="supports_expiration",
field=models.BooleanField(default=False, help_text="Indicates if the enrollment expires or does not expire"),
),
migrations.RunPython(migrate_data),
migrations.RenameField(
model_name="enrollmentflow",
old_name="name",
new_name="system_name",
),
migrations.RemoveField(
model_name="enrollmentflow",
name="eligibility_type",
),
migrations.RemoveField(
model_name="transitagency",
name="eligibility_types",
),
migrations.DeleteModel(
name="EligibilityType",
),
]
73 changes: 20 additions & 53 deletions benefits/core/migrations/local_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,57 +39,14 @@
}
},
{
"model": "core.eligibilitytype",
"model": "core.enrollmentflow",
"pk": 1,
"fields": {
"name": "senior",
"system_name": "senior",
"label": "(CST) Senior Discount",
"group_id": "group123",
"enrollment_success_template": "enrollment/success--cst.html"
}
},
{
"model": "core.eligibilitytype",
"pk": 2,
"fields": {
"name": "veteran",
"label": "(CST) Veteran Discount",
"group_id": "group123",
"enrollment_success_template": "enrollment/success--cst.html"
}
},
{
"model": "core.eligibilitytype",
"pk": 3,
"fields": {
"name": "agency_card",
"label": "(CST) Agency Card Discount",
"group_id": "group123",
"enrollment_index_template": "enrollment/index--agency-card.html",
"enrollment_success_template": "enrollment/success--cst-agency-card.html"
}
},
{
"model": "core.eligibilitytype",
"pk": 4,
"fields": {
"name": "calfresh",
"label": "CalFresh",
"group_id": "group123",
"supports_expiration": "True",
"expiration_days": 5,
"expiration_reenrollment_days": 3,
"reenrollment_error_template": "enrollment/reenrollment-error--calfresh.html",
"enrollment_success_template": "enrollment/success--cst.html"
}
},
{
"model": "core.enrollmentflow",
"pk": 1,
"fields": {
"name": "(CST) oauth claims via Login.gov",
"enrollment_success_template": "enrollment/success--cst.html",
"display_order": 1,
"eligibility_type": 1,
"claims_provider": 1,
"selection_label_template": "eligibility/includes/selection-label--senior.html",
"eligibility_start_template": "eligibility/start--senior.html",
Expand All @@ -101,9 +58,11 @@
"model": "core.enrollmentflow",
"pk": 2,
"fields": {
"name": "(CST) VA.gov - veteran",
"system_name": "veteran",
"label": "(CST) Veteran Discount",
"group_id": "group123",
"enrollment_success_template": "enrollment/success--cst.html",
"display_order": 3,
"eligibility_type": 2,
"claims_provider": 1,
"selection_label_template": "eligibility/includes/selection-label--veteran.html",
"eligibility_start_template": "eligibility/start--veteran.html",
Expand All @@ -115,12 +74,15 @@
"model": "core.enrollmentflow",
"pk": 3,
"fields": {
"name": "(CST) eligibility server flow",
"system_name": "agency_card",
"label": "(CST) Agency Card Discount",
"group_id": "group123",
"enrollment_index_template": "enrollment/index--agency-card.html",
"enrollment_success_template": "enrollment/success--cst-agency-card.html",
"display_order": 4,
"eligibility_api_url": "http://server:8000/verify",
"eligibility_api_auth_header": "X-Server-API-Key",
"eligibility_api_auth_key_secret_name": "agency-card-flow-api-auth-key",
"eligibility_type": 3,
"eligibility_api_public_key": 1,
"eligibility_api_jwe_cek_enc": "A256CBC-HS512",
"eligibility_api_jwe_encryption_alg": "RSA-OAEP",
Expand All @@ -136,9 +98,15 @@
"model": "core.enrollmentflow",
"pk": 4,
"fields": {
"name": "(CST) CalFresh oauth claims via Login.gov",
"system_name": "calfresh",
"label": "CalFresh",
"group_id": "group123",
"supports_expiration": "True",
"expiration_days": 5,
"expiration_reenrollment_days": 3,
"reenrollment_error_template": "enrollment/reenrollment-error--calfresh.html",
"enrollment_success_template": "enrollment/success--cst.html",
"display_order": 2,
"eligibility_type": 4,
"claims_provider": 1,
"selection_label_template": "eligibility/includes/selection-label--calfresh.html",
"eligibility_start_template": "eligibility/start--calfresh.html",
Expand All @@ -163,7 +131,6 @@
"pk": 1,
"fields": {
"active": true,
"eligibility_types": [1, 2, 3, 4],
"enrollment_flows": [1, 2, 3, 4],
"slug": "cst",
"short_name": "CST (local)",
Expand Down
Loading
Loading