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: rename EligibilityVerifier to EnrollmentFlow #2293

Merged
merged 8 commits into from
Aug 13, 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
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DJANGO_DB_FILE=django.db
DJANGO_DB_FIXTURES="benefits/core/migrations/local_fixtures.json"

claims_provider_client_id=benefits-oauth-client-id
agency_card_verifier_api_auth_key=server-auth-token
agency_card_flow_api_auth_key=server-auth-token
client_private_key='-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA1pt0ZoOuPEVPJJS+5r884zcjZLkZZ2GcPwr79XOLDbOi46on\nCa79kjRnhS0VUK96SwUPS0z9J5mDA5LSNL2RoxFb5QGaevnJY828NupzTNdUd0sY\nJK3kRjKUggHWuB55hwJcH/Dx7I3DNH4NL68UAlK+VjwJkfYPrhq/bl5z8ZiurvBa\n5C1mDxhFpcTZlCfxQoas7D1d+uPACF6mEMbQNd3RaIaSREO50NvNywXIIt/OmCiR\nqI7JtOcn4eyh1I4j9WtlbMhRJLfwPMAgY5epTsWcURmhVofF2wVoFbib3JGCfA7t\nz/gmP5YoEKnf/cumKmF3e9LrZb8zwm7bTHUViwIDAQABAoIBAQCIv0XMjNvZS9DC\nXoXGQtVpcxj6dXfaiDgnc7hZDubsNCr3JtT5NqgdIYdVNQUABNDIPNEiCkzFjuwM\nuuF2+dRzM/x6UCs/cSsCjXYBCCOwMwV/fjpEJQnwMQqwTLulVsXZYYeSUtXVBf/8\n0tVULRty34apLFhsyX30UtboXQdESfpmm5ZsqsZJlYljw+M7JxRMneQclI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----END RSA PRIVATE KEY-----'
client_public_key='-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1pt0ZoOuPEVPJJS+5r88\n4zcjZLkZZ2GcPwr79XOLDbOi46onCa79kjRnhS0VUK96SwUPS0z9J5mDA5LSNL2R\noxFb5QGaevnJY828NupzTNdUd0sYJK3kRjKUggHWuB55hwJcH/Dx7I3DNH4NL68U\nAlK+VjwJkfYPrhq/bl5z8ZiurvBa5C1mDxhFpcTZlCfxQoas7D1d+uPACF6mEMbQ\nNd3RaIaSREO50NvNywXIIt/OmCiRqI7JtOcn4eyh1I4j9WtlbMhRJLfwPMAgY5ep\nTsWcURmhVofF2wVoFbib3JGCfA7tz/gmP5YoEKnf/cumKmF3e9LrZb8zwm7bTHUV\niwIDAQAB\n-----END PUBLIC KEY-----'
cst_transit_processor_client_secret=secret
Expand Down
4 changes: 2 additions & 2 deletions benefits/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def get_readonly_fields(self, request, obj=None):
return super().get_readonly_fields(request, obj)


@admin.register(models.EligibilityVerifier)
class SortableEligibilityVerifierAdmin(SortableAdminMixin, admin.ModelAdmin): # pragma: no cover
@admin.register(models.EnrollmentFlow)
class SortableEnrollmentFlowAdmin(SortableAdminMixin, admin.ModelAdmin): # pragma: no cover
def get_exclude(self, request, obj=None):
if not request.user.is_superuser:
return [
Expand Down
4 changes: 2 additions & 2 deletions benefits/core/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, request, event_type, **kwargs):

agency = session.agency(request)
agency_name = agency.long_name if agency else None
verifier = session.verifier(request)
verifier_name = verifier.name if verifier else None
flow = session.flow(request)
verifier_name = flow.name if flow else None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want to use flow_name instead of verifier_name? Or maybe we decided to use this name since the analytics will still send eligibility_verifier/verifier_name key/values in update_event_properties and update_user_properties. It doesn't affect any functionality but I was wondering about this line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it needs to stay verifier_name so that existing analytics charts still work and then #2248 will take care of updating it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, purposefully ignored the analytics code in this PR, to wait for #2248

eligibility_types = session.eligibility(request)
eligibility_types = EligibilityType.get_names(eligibility_types) if eligibility_types else None

Expand Down
14 changes: 7 additions & 7 deletions benefits/core/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def unique_values(original_list):
return list(dict.fromkeys(original_list))


def _agency_context(agency):
def _agency_context(agency: models.TransitAgency):
return {
"eligibility_index_url": agency.eligibility_index_url,
"help_templates": unique_values([v.help_template for v in agency.active_verifiers if v.help_template]),
"help_templates": unique_values([f.help_template for f in agency.enrollment_flows.all() if f.help_template]),
"info_url": agency.info_url,
"long_name": agency.long_name,
"phone": agency.phone,
Expand Down Expand Up @@ -48,16 +48,16 @@ def analytics(request):

def authentication(request):
"""Context processor adds authentication information to request context."""
verifier = session.verifier(request)
flow = session.flow(request)

if verifier:
if flow:
data = {
"logged_in": session.logged_in(request),
}

if verifier.uses_claims_verification:
data["sign_out_button_template"] = verifier.claims_provider.sign_out_button_template
data["sign_out_link_template"] = verifier.claims_provider.sign_out_link_template
if flow.uses_claims_verification:
data["sign_out_button_template"] = flow.claims_provider.sign_out_button_template
data["sign_out_link_template"] = flow.claims_provider.sign_out_link_template

return {"authentication": data}
else:
Expand Down
16 changes: 8 additions & 8 deletions benefits/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ def process_request(self, request):
return self.get_response(request)


class VerifierSessionRequired(MiddlewareMixin):
"""Middleware raises an exception for sessions lacking an eligibility verifier configuration."""
class FlowSessionRequired(MiddlewareMixin):
"""Middleware raises an exception for sessions lacking a configured enrollment flow."""

def process_request(self, request):
if session.verifier(request):
logger.debug("Session configured with eligibility verifier")
if session.flow(request):
logger.debug("Session configured with enrollment flow")
return None
else:
logger.debug("Session not configured with eligibility verifier")
logger.debug("Session not configured with enrollment flow")
return user_error(request)


Expand Down Expand Up @@ -129,9 +129,9 @@ class LoginRequired(MiddlewareMixin):
"""Middleware that checks whether a user is logged in."""

def process_view(self, request, view_func, view_args, view_kwargs):
# only require login if verifier uses claims verification
verifier = session.verifier(request)
if not verifier or not verifier.uses_claims_verification or session.logged_in(request):
# only require login if flow uses claims verification
flow = session.flow(request)
if not flow or not flow.uses_claims_verification or session.logged_in(request):
# pass through
return None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from django.contrib.auth.management import create_permissions
from django.db import migrations


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
from benefits.core.migrations import create_all_permissions


def add_view_permissions(apps, schema_editor):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Generated by Django 5.0.7 on 2024-07-31 22:41

from django.contrib.auth.management import create_permissions
from django.db import migrations, models

from benefits.core.migrations import create_all_permissions
import benefits.core.models
import benefits.secrets


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None


def update_permissions(apps, schema_editor):
Group = apps.get_model("auth", "Group")
staff_group = Group.objects.get(name="Cal-ITP")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
# Generated by Django 5.0.7 on 2024-08-02 22:52

from django.contrib.auth.management import create_permissions
from django.db import migrations, models

from benefits.core.migrations import create_all_permissions
import benefits.core.models
import benefits.secrets


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None


def update_permissions(apps, schema_editor):
# delete old permissions
Permission = apps.get_model("auth", "Permission")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Generated by Django 5.0.7 on 2024-08-07 21:22

import django.db.models.deletion
from django.db import migrations, models

import benefits.core.models
import benefits.secrets
from benefits.core.migrations import create_all_permissions


def update_permissions(apps, schema_editor):
Group = apps.get_model("auth", "Group")
staff_group = Group.objects.get(name="Cal-ITP")

Permission = apps.get_model("auth", "Permission")

remove_permissions = ["Can view", "Can change", "Can add", "Can delete"]
for remove_permission in remove_permissions:
current_permission = Permission.objects.get(name=f"{remove_permission} eligibility verifier")
staff_group.permissions.remove(current_permission)
current_permission.delete()

add_permissions = ["Can view", "Can change"]
for add_permission in add_permissions:
new_permission = Permission.objects.get(name=f"{add_permission} enrollment flow")
staff_group.permissions.add(new_permission)


class Migration(migrations.Migration):

dependencies = [
("core", "0020_refactor_idg_config_eligibilityverifier"),
]

operations = [
migrations.RenameModel(
old_name="EligibilityVerifier",
new_name="EnrollmentFlow",
),
migrations.RenameField(
model_name="transitagency",
old_name="eligibility_verifiers",
new_name="enrollment_flows",
),
migrations.RemoveField(
model_name="enrollmentflow",
name="active",
),
migrations.AlterField(
model_name="enrollmentflow",
name="claims_provider",
field=models.ForeignKey(
blank=True,
help_text="An entity that provides claims for eligibility verification for this flow.",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="core.claimsprovider",
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_auth_header",
field=models.TextField(
blank=True, help_text="The auth header to send in Eligibility API requests for this flow.", null=True
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_auth_key_secret_name",
field=benefits.core.models.SecretNameField(
blank=True,
help_text="The name of a secret containing the value of the auth header to send in Eligibility API requests for this flow.", # noqa: E501
max_length=127,
null=True,
validators=[benefits.secrets.SecretNameValidator()],
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_jwe_cek_enc",
field=models.TextField(
blank=True,
help_text="The JWE-compatible Content Encryption Key (CEK) key-length and mode to use in Eligibility API requests for this flow.", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_jwe_encryption_alg",
field=models.TextField(
blank=True,
help_text="The JWE-compatible encryption algorithm to use in Eligibility API requests for this flow.",
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_jws_signing_alg",
field=models.TextField(
blank=True,
help_text="The JWS-compatible signing algorithm to use in Eligibility API requests for this flow.",
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_public_key",
field=models.ForeignKey(
blank=True,
help_text="The public key used to encrypt Eligibility API requests and to verify signed Eligibility API responses for this flow.", # noqa: E501
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="core.pemdata",
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_api_url",
field=models.TextField(
blank=True, help_text="Fully qualified URL for an Eligibility API server used by this flow.", null=True
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_form_class",
field=models.TextField(
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
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_start_template",
field=models.TextField(
default="eligibility/start.html",
help_text="Path to a Django template for the informational page of this flow.",
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="eligibility_unverified_template",
field=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.", # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="help_template",
field=models.TextField(
blank=True,
help_text="Path to a Django template that defines the help text for this enrollment flow, used in building the dynamic help page for an agency", # noqa: E501
null=True,
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="name",
field=models.TextField(
help_text="Primary internal system name for this EnrollmentFlow instance, e.g. in analytics and Eligibility API requests." # noqa: E501
),
),
migrations.AlterField(
model_name="enrollmentflow",
name="selection_label_template",
field=models.TextField(
help_text="Path to a Django template that defines the end-user UI for selecting this flow among other options."
),
),
migrations.RunPython(create_all_permissions),
migrations.RunPython(update_permissions),
]
8 changes: 8 additions & 0 deletions benefits/core/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib.auth.management import create_permissions


def create_all_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, apps=apps, verbosity=0)
app_config.models_module = None
Loading
Loading