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: field defaults, optional fields, templates #2471

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

thekaveman
Copy link
Member

@thekaveman thekaveman commented Oct 22, 2024

This PR is another step along the way of making it easier and faster to configure new TransitAgency and EnrollmentFlow instances, while also ensuring a valid configuration for instances that are going live on the app.

Changes

TransitAgency

  • Make the slug field a Django SlugField to enforce the slugness; this field is now used to calculate template paths as well
  • Make all Eligibility API fields, Transit Processor API fields optional
  • Defaults for info fields e.g. long_name, phone from CST defaults
  • Calculate sane defaults for templates from the slug following our established pattern, e.g. core/index--{slug}.html and eligibility/index--{slug}.html
  • Retain ability to override templates if needed
  • Setting active=True validates some fields (e.g. info fields, templates must exist)

EnrollmentFlow

  • Make the system_name field a Django SlugField to enforce slugness; this field is now used to calculate template paths as well
  • Make all template fields optional
  • Calculate sane defaults for templates from the system_name or slug following our established pattern, e.g. eligibility/start--{system_name}.html and enrollment/success--{slug}.html
  • Remove the specific name of the agency card from templates, like courtesy-card
  • Calculate defaults specific to Agency Card flows establishing a new pattern, e.g. eligibility/start--{slug}-agency-card.html
  • Retain ability to override templates if needed
  • When the EnrollmentFlow has an active TransitAgency, validates that templates exist and that either claims verification or Eligibility API verification is configured correctly.

Reviewing

  1. Check out this branch locally
  2. Delete your database
  3. Run bin/reset_db.sh with default fixtures
  4. Launch the app
  5. Run through various flows, ensure no regressions
  6. Sign in to the Admin
  7. Verify that new TransitAgency instances can be created with only the slug field provided
  8. Verify that saving an active TransitAgency requires certain info fields to have values
  9. Verify that saving an active TransitAgency requires templates to exist, and the defaults are calculated from the slug)
  10. Verify that saving an EnrollmentFlow with an active TransitAgency requires a valid claims or Eligibility API verification configuration
  11. Verify that saving an EnrollmentFlow with an active TransitAgency requires templates to exist, and defaults are calculated from the system_name or TransitAgency.slug.

@github-actions github-actions bot added front-end HTML/CSS/JavaScript and Django templates back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev migrations [auto] Review for potential model changes/needed data migrations updates tests Related to automated testing (unit, UI, integration, etc.) and removed deployment-dev [auto] Changes that will trigger a deploy if merged to dev labels Oct 22, 2024
Copy link

github-actions bot commented Oct 22, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  admin.py
  context_processors.py
  models.py
  benefits/enrollment
  views.py
Project Total  

This report was generated by python-coverage-comment-action

@thekaveman thekaveman added the deployment-dev [auto] Changes that will trigger a deploy if merged to dev label Oct 22, 2024
@thekaveman thekaveman self-assigned this Oct 22, 2024
@thekaveman thekaveman marked this pull request as ready for review October 29, 2024 15:11
@thekaveman thekaveman requested a review from a team as a code owner October 29, 2024 15:11
@thekaveman thekaveman marked this pull request as draft October 29, 2024 15:23
@thekaveman thekaveman force-pushed the refactor/field-defaults branch 2 times, most recently from a088943 to 54b2042 Compare October 29, 2024 15:30
@thekaveman thekaveman marked this pull request as ready for review October 29, 2024 15:40
@thekaveman thekaveman marked this pull request as draft October 29, 2024 18:22
@thekaveman thekaveman force-pushed the refactor/field-defaults branch 4 times, most recently from 56165d4 to 6012bff Compare November 6, 2024 00:44
@thekaveman thekaveman force-pushed the refactor/field-defaults branch 2 times, most recently from 321538f to 7759cc7 Compare November 12, 2024 23:16
@thekaveman thekaveman changed the base branch from main to feat/admin-agency-logos November 12, 2024 23:17
@lalver1 lalver1 force-pushed the feat/admin-agency-logos branch 5 times, most recently from 6f4337f to e255665 Compare November 14, 2024 21:52
@thekaveman thekaveman marked this pull request as ready for review November 19, 2024 00:11
@thekaveman thekaveman changed the title Refactor: field defaults for optional fields, templates Refactor: field defaults, optional fields, templates Nov 19, 2024
@thekaveman thekaveman marked this pull request as draft November 19, 2024 00:22
@thekaveman thekaveman force-pushed the refactor/field-defaults branch 2 times, most recently from 9abea1b to 6bed021 Compare November 19, 2024 00:41
@thekaveman thekaveman marked this pull request as ready for review November 19, 2024 00:41
@thekaveman thekaveman marked this pull request as draft November 19, 2024 16:20
@thekaveman thekaveman force-pushed the refactor/field-defaults branch 3 times, most recently from e73e3df to b413ddc Compare November 19, 2024 22:27
@thekaveman thekaveman marked this pull request as ready for review November 19, 2024 22:31
lalver1
lalver1 previously approved these changes Nov 21, 2024
Copy link
Member

@lalver1 lalver1 left a comment

Choose a reason for hiding this comment

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

I tested running through these flows and they all looked good:

  • Medicare ✅
  • Older Adult ✅
  • Calfresh ✅
  • Veteran ✅
  • Agency Card ✅

These admin panel actions also behaved as expected:

  1. New TransitAgency instances can be created with only the slug field provided ✅
  2. Saving an active TransitAgency requires certain info fields to have values ✅
  3. Saving an active TransitAgency requires templates to exist (and the defaults are calculated from the slug) ✅
  4. Saving an EnrollmentFlow with an active TransitAgency requires templates to exist, and defaults are calculated from the system_name or TransitAgency.slug

At first I was a bit confused about action 4 above, because to review I created a new EnrollmentFlow without claims information for an active agency and so what I got in the eligibility form was another Agency Cardholder radio input identical to the existing one. But this is completely normal and basically shows that for a case like this, overriding the selection label template would be needed.

image

@thekaveman
Copy link
Member Author

I created a new EnrollmentFlow without claims information for an active agency

Hmmm... this seems like it should be an error. I.e. we should have either claims information or Eligibility API information on the flow for an active agency.

Seems like this is something we should check for in the clean() -- thoughts?

@lalver1
Copy link
Member

lalver1 commented Nov 22, 2024

Yep, now that I look at it again, I feel it should be an error. I think that if we add something like

if self.claims_provider and not bool(self.claims_scope):
    errors.update(claims_scope=ValidationError("Missing scope"))

if self.claims_provider and not bool(self.claims_eligibility_claim):
    errors.update(claims_eligibility_claim=ValidationError("Missing eligibility claim"))

to clean() anywhere before

if errors:
   raise ValidationError(errors)

then the form will give a validation error if a claims_provider has been selected but no scope/claim has been entered. Then let's suppose that the scope/claim info is entered but templates have not been created, then the existing template validation section of clean() (starting on line 624) will correctly return that the template was not found.

I think a similar check should happen if it is an Eligibility API flow. Currently if self.claims_provider is blank, we can still save the flow and another Agency Cardholder radio input identical to the existing one is displayed.

- compute template fields by default
- allow overriding templates
- compute some template fields by default
- allow overriding 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
- use CST defaults for user-facing fields
- allow blanks for config fields
- remove null from TextField, not needed when blank=True
when active=True, validate that:

- there are values for user-facing info fields like names, logos, phone, etc.
- templates exist
when the flow's agency.active=True, validate that templates exist

consolidate other EnrollmentFlow.clean() tests
@thekaveman thekaveman marked this pull request as draft November 23, 2024 00:11
change default to empty string

these are stored as the empty string when blank=True
Django recommends against null=True on TextFields: https://docs.djangoproject.com/en/5.1/ref/models/fields/#null
keep track of all field and template errors separately

raise a ValidationError from either when present
this field is now captured on EnrollmentFlow with the other
Eligibility API fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. deployment-dev [auto] Changes that will trigger a deploy if merged to dev front-end HTML/CSS/JavaScript and Django templates migrations [auto] Review for potential model changes/needed data migrations updates tests Related to automated testing (unit, UI, integration, etc.)
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants