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

Feat: store/retrieve enrollment expiry in session #1985

Merged
merged 4 commits into from
Mar 26, 2024

Conversation

thekaveman
Copy link
Member

@thekaveman thekaveman commented Mar 26, 2024

Closes #1981

New session helpers:

  • enrollment_expiry gets the current user's expiration as a datetime, or None
  • enrollment_reenrollment gets the current user's reenrollment as a datetime, or None
  • update accepts enrollment_expiry as a datetime

New context_processor:

  • Adds expiration, reenrollment, and supports_expiration under the enrollment key
{ 
  "enrollment": {
    "expiration": datetime | None,
    "reenrollment": datetime | None, 
    "supports_expiration": bool
  }
}

Also removed most of the noisy logging from session.

these cause a lot of noise in our logs and aren't very useful
@thekaveman thekaveman self-assigned this Mar 26, 2024
@github-actions github-actions bot added deployment-dev [auto] Changes that will trigger a deploy if merged to dev tests Related to automated testing (unit, UI, integration, etc.) back-end Django views, sessions, middleware, models, migrations etc. and removed tests Related to automated testing (unit, UI, integration, etc.) labels Mar 26, 2024
Copy link

github-actions bot commented Mar 26, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core
  context_processors.py
  session.py
Project Total  

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

returned expiry datetime is always an aware datetime instance in UTC
@thekaveman thekaveman force-pushed the feat/enrollment-expiry-session branch from fda313f to 09cbaed Compare March 26, 2024 00:24
@thekaveman thekaveman marked this pull request as ready for review March 26, 2024 15:50
@thekaveman thekaveman requested a review from a team as a code owner March 26, 2024 15:50
@thekaveman thekaveman marked this pull request as draft March 26, 2024 16:01
@thekaveman thekaveman marked this pull request as ready for review March 26, 2024 16:21
Copy link
Member

@angela-tran angela-tran left a comment

Choose a reason for hiding this comment

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

This looks great! I thought through the implications of having the session calculate the reenrollment date every time (as opposed to having the view set it on the session), and that seems fine to me.

@angela-tran
Copy link
Member

I thought through the implications of having the session calculate the reenrollment date every time (as opposed to having the view set it on the session), and that seems fine to me.

I think it does mean that there's no need for any expiration.calculate_reenrollment_date function

@thekaveman
Copy link
Member Author

I thought through the implications of having the session calculate the reenrollment date every time (as opposed to having the view set it on the session), and that seems fine to me.

I think it does mean that there's no need for any expiration.calculate_reenrollment_date function

Hmm good point.

I think for the first thought, it seems OK for the reenrollment date to be recalculated each time (regardless of where) since it is a fixed offset from the known/stored expiration date.

For the second thought (where to do this calculation) -- I'm open. My thinking was it made sense to put it here since the session will be the "source of truth" for the expiration date for the rest of the app, so it could also be the "source of truth" for the reenrollment date. It does sort of abuse the session and put business logic there, rather than just storing data... so I'm open to moving this out.

@angela-tran
Copy link
Member

My thinking was it made sense to put it here since the session will be the "source of truth" for the expiration date for the rest of the app, so it could also be the "source of truth" for the reenrollment date.

Yeah, I think ultimately we need the reenrollment date in the context processor and therefore need it on the session. As for if the the calculation is done directly inside the session module or is in a separate module that is called by session, I don't think it makes a big difference in this PR.

Maybe in my PR I can move the calculation into benefits.enrollment.expiration?

@thekaveman
Copy link
Member Author

My thinking was it made sense to put it here since the session will be the "source of truth" for the expiration date for the rest of the app, so it could also be the "source of truth" for the reenrollment date.

Yeah, I think ultimately we need the reenrollment date in the context processor and therefore need it on the session. As for if the the calculation is done directly inside the session module or is in a separate module that is called by session, I don't think it makes a big difference in this PR.

Maybe in my PR I can move the calculation into benefits.enrollment.expiration?

Hmmm but the problem is we can't/don't want benefits.core.session to depend on/import benefits.enrollment.expiration, the imports typically go the other way (and we might run into a circular import issue if we try to go this way).

@angela-tran
Copy link
Member

Hmmm but the problem is we can't/don't want benefits.core.session to depend on/import benefits.enrollment.expiration, the imports typically go the other way (and we might run into a circular import issue if we try to go this way).

Oh I see. I'm leaning now towards just keeping it in benefits.core.session. The business logic is not complicated, and the value is derived from something that was set on the session.

@thekaveman thekaveman merged commit 3b6c386 into dev Mar 26, 2024
13 checks passed
@thekaveman thekaveman deleted the feat/enrollment-expiry-session branch March 26, 2024 21:20
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Session stores enrollment expiration, context processor makes available to templates
2 participants