-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor: Eligibility API config models #3232
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
base: main
Are you sure you want to change the base?
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
replace EnrollmentFlow optional config fields with an optional foreign key
refactor EnrollmentFlow.clean() to use the new api_request field
replace TransitAgency optional config fields with an optional foreign key
1b8b342
to
2973c95
Compare
2973c95
to
8d04366
Compare
Resolved. Forgot that the group IDs needed to be updated in my local config. |
Also note that this PR doesn't have anything to do with Enrollment, so I wouldn't expect that to necessarily be a part of the review process. Glad you got it sorted though! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All seems to be working well! I left a few non-blocking questions and comments inline.
P.S.: I did also run the migration against a DB initiated on main
and the data was migrated as expected.
api_id = models.SlugField( | ||
help_text="The identifier for this agency used in Eligibility API calls.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Should we be using our list of slugs to limit the choices here, or could this possibly be a different slug for the Eligibility API?
api_id = models.SlugField( | |
help_text="The identifier for this agency used in Eligibility API calls.", | |
) | |
api_id = models.SlugField( | |
choices=core_context.AgencySlug, | |
help_text="The identifier for this agency used in Eligibility API calls.", | |
) |
If they do always match, another option could be OneToOneField
to the TransitAgency
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the question. At this point it really doesn't matter that much -- we don't expect to ever create a new instance of this model (deploy a new Eligibility Server). Keeping it a looser relationship/label allows more flexibility if we want to e.g. create multiple agencies/flows quickly for testing.
label = models.SlugField( | ||
help_text="A human readable label, used as the display text in Admin.", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The label you added in the fixture is just agency_card
, but I'd expect it to have a reference to the agency itself when there are multiple in play, and I'd mention that in the help text.
Alternatively, since this seems to just be used for the Admin display, we could modify the __str__
to something like this and then use that in list_display
and get rid of label
completely.
def __str__(self):
try:
# If an EnrollmentFlow has selected this for its api_request field, use that EnrollmentFlow's string representation
return EnrollmentFlow.objects.get(api_request=self).__str__()
except EnrollmentFlow.DoesNotExist:
# Otherwise return a string indicating it's not in use yet
return "unassociated"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agency_card
is what we call the generic CST version of agency cards -- the value already exists in the fixture like that: https://github.com/cal-itp/benefits/blob/main/benefits/core/migrations/local_fixtures.json#L248 and in the code e.g. https://github.com/cal-itp/benefits/blob/main/benefits/core/context/flow.py#L8
(Yes, this field isn't the "same" as a system name, but as far as the data migration goes, it gets populated with the same value).
Again, we don't expect to need to do much with these fields/models. The whole reason of ripping it out of the TransitAgency
and EnrollmentFlow
models, to get them out of the way.
I like your suggestion to calc the label for the Admin, I'm just not inclined to write (and test) more code for this niche use case. It also means that the selection UI from the EnrollmentFlow
side shows a list of unassociated
with no way to differentiate between them.
label = models.SlugField( | ||
help_text="A human readable label, used as the display text in Admin.", | ||
) | ||
api_url = models.URLField(help_text="Fully qualified URL for an Eligibility API server.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL that any host without a TLD will be rejected by Django's URLValidator unless it's localhost
. That means we can never re-save or manually re-create the one being set up by the fixtures pointing to our local server:8000
host. It's a fairly academic concern, since I doubt most people will ever need to do that, but thought I'd mention it just in case you care. I only ran across it when adding a new item to test my __str__
suggestion above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know 🤓 I didn't know that either (you'll notice I changed from a TextField
to a URLField
not even thinking about this).
But yeah, probably not a situation we have to be too worried about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Would it be worth making this migration reversible? I'm used to "failing forward" when things don't go as expected, so it doesn't worry me that much, but then again I have mostly been working on content sites where a temporary breakage doesn't have as much impact as an app like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, we kind of just move forward too, I don't think we've ever done a reversible migration?
Closes #2780
What this PR does
EligibilityApiConfig
for agency-specific Eligibility API data (public/private client keys)TransitAgency
with Eligibility API configTransitAgency
, adds optional foreign key toEligibilityApiConfig
EligibilityApiVerificationRequest
for flow-specific Eligibility API data (keys, JWT config)EnrollmentFlow
with Eligibility API configEnrollmentFlow
, adds optional foreign key toEligibilityApiVerificationRequest
The idea is to make configuration of flows simpler going forward, as we don't expect to use this API for new flows, simply maintaining the existing 2 in production (MST Courtesy Cards, SBMTD Reduced Fare Mobility ID).
The
EligibilityApiConfig
changes weren't necessarily spelled out in #2780. However they are similar enough, and similarly meant to make theTransitAgency
configuration experience simpler for agencies going forward.Testing the PR
User flow
local_fixtures.json
from the branchAdmin (superuser)
Admin (Cal-ITP user)