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

fix: send LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED from the correct place. #2234

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

pwnage101
Copy link
Contributor

@pwnage101 pwnage101 commented Sep 6, 2024

I had originally tried emitting this event from the /cancel_enrollment
API endpoint, but in reality the LMS and Enterprise dashboards were
calling the /change_enrollment endpoint. The former is called by
enterprise-subsidy on transaction reversal, i.e. NOT learner-initiated.
The latter is learner-initiated, and that's the original goal of this
work.

Changes in this commit:

  • Update the event emission to live closer to the fulfillment
    model itself (inside revoke()).
  • Ensure that when an EnterpriseCourseEnrollment is unenrolled, the
    related Fulfillment subclass is revoked. This is a best-effort to
    improve internal consistency during learner-initiated unenrollment.
  • Consumers of the various enrollment models are now expected to call
    helper functions to unenroll/reenroll/revoke/reactivate rather than
    directly set internal fields.

ENT-9213

@pwnage101 pwnage101 marked this pull request as draft September 6, 2024 19:16
@pwnage101 pwnage101 force-pushed the pwnage101/ENT-9213-2 branch 4 times, most recently from 95248e6 to 4b57f58 Compare September 9, 2024 23:06
@pwnage101 pwnage101 marked this pull request as ready for review September 9, 2024 23:07
Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

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

Looks good, one small question to maybe improve comprehensibility.

enterprise/models.py Show resolved Hide resolved
Comment on lines 2120 to 2124
def fulfillment(self):
"""
Find and return the related EnterpriseFulfillmentSource subclass, or None.
"""
return self.license or self.learner_credit_fulfillment
Copy link
Member

Choose a reason for hiding this comment

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

[curious] Likely edge casey, but is it possible for the same EnterpriseCourseEnrollment to be re-used across multiple fulfillment sources, e.g. both a license and learner credit? For example, if the learner has enrolled previously with subscriptions, unenrolled, and then re-enrolled with learner credit instead (e.g., the customer switched subsidy types), and then unenrolled again. Would we want this to prioritize only revoking the self.license in this case, or would we expect to revoke both fulfillment sources?

Copy link
Contributor

Choose a reason for hiding this comment

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

Great querstion! Since EnterpriseFulfillmentSource.enterprise_course_enrollment is a 1-1 field, its not possible for two different fulfillment source records to point at the same ECE record (OneToOneFields are just unique FKs).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do think adam might be right because the subclasses of EnterpriseFulfillmentSource become separate physical tables. While the relationship between an ECE <-> LC fulfillment is 1:1, and ECE <-> Licensed fulfillment is also 1:1, that doesn't technically stop an ECE from being related to an LC and Licensed fulfillment simultaneously. I think we rely solely on business logic to protect against this case.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

LGTM, beyond the curiosity question about the edge case of whether it's possible to have an EnterpriseCourseEnrollment with multiple fulfillment sources simutaneously.

…lace.

I had originally tried emitting this event from the `/cancel_enrollment`
API endpoint, but in reality the LMS and Enterprise dashboards were
calling the `/change_enrollment` endpoint.  The former is called by
enterprise-subsidy on transaction reversal, i.e. NOT learner-initiated.
The latter is learner-initiated, and that's the original goal of this
work.

Changes in this commit:
* Update the event emission to live closer to the fulfillment
  model itself (inside `revoke()`).
* Ensure that when an EnterpriseCourseEnrollment is unenrolled, the
  related Fulfillment subclass is revoked. This is a best-effort to
  improve internal consistency during learner-initiated unenrollment.
* Consumers of the various enrollment models are now expected to call
  helper functions to unenroll/reenroll/revoke/reactivate rather than
  directly set internal fields.

ENT-9213
@pwnage101 pwnage101 merged commit 2ac5dae into master Sep 10, 2024
11 checks passed
@pwnage101 pwnage101 deleted the pwnage101/ENT-9213-2 branch September 10, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants