Skip to content

Commit

Permalink
Merge pull request #2190 from openedx/pwnage101/ENT-9213
Browse files Browse the repository at this point in the history
feat: emit learner credit unenrollment event
  • Loading branch information
pwnage101 authored Sep 5, 2024
2 parents f8ea429 + a61ee2d commit d880ce8
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Unreleased
----------
* nothing unreleased

[4.25.0]
----------
* feat: emit learner credit unenrollment event

[4.24.0]
----------
* fix: customer sorting error in customer support tool endpoint and added user query param
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.24.0"
__version__ = "4.25.0"
3 changes: 3 additions & 0 deletions enterprise/api/v1/views/enterprise_subsidy_fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def unenrolled(self, request, *args, **kwargs):
retrieve_licensed_enrollments (bool): If true, return data related to licensed enrollments instead of
learner credit
"""
LOGGER.warning(
"[DEPRECATION] This view is deprecated for lack of purpose. Logging to confirm utilization drop-off.",
)
queryset = self._get_unenrolled_fulfillments()
serializer_class = self.get_unenrolled_fulfillment_serializer_class()
serializer = serializer_class(queryset, many=True)
Expand Down
70 changes: 70 additions & 0 deletions enterprise/event_bus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Functions for serializing and emiting Open edX event bus signals.
"""
from openedx_events.enterprise.data import (
EnterpriseCourseEnrollment,
EnterpriseCustomerUser,
LearnerCreditEnterpriseCourseEnrollment,
)
from openedx_events.enterprise.signals import LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED


def serialize_learner_credit_course_enrollment(learner_credit_course_enrollment):
"""
Serializes the ``LearnerCreditEnterpriseCourseEnrollment`` into a defined set of attributes
for use in the event-bus signal.
"""
enterprise_course_enrollment = learner_credit_course_enrollment.enterprise_course_enrollment
enterprise_customer_user = enterprise_course_enrollment.enterprise_customer_user

enterprise_customer_user_data = EnterpriseCustomerUser(
id=enterprise_customer_user.id,
created=enterprise_customer_user.created,
modified=enterprise_customer_user.modified,
enterprise_customer_uuid=enterprise_customer_user.enterprise_customer.uuid,
user_id=enterprise_customer_user.user_id,
active=enterprise_customer_user.active,
linked=enterprise_customer_user.linked,
is_relinkable=enterprise_customer_user.is_relinkable,
invite_key=enterprise_customer_user.invite_key.uuid if enterprise_customer_user.invite_key else None,
should_inactivate_other_customers=enterprise_customer_user.should_inactivate_other_customers,
)
enterprise_course_enrollment_data = EnterpriseCourseEnrollment(
id=enterprise_course_enrollment.id,
created=enterprise_course_enrollment.created,
modified=enterprise_course_enrollment.modified,
enterprise_customer_user=enterprise_customer_user_data,
course_id=enterprise_course_enrollment.course_id,
saved_for_later=enterprise_course_enrollment.saved_for_later,
source_slug=enterprise_course_enrollment.source.slug if enterprise_course_enrollment.source else None,
unenrolled=enterprise_course_enrollment.unenrolled,
unenrolled_at=enterprise_course_enrollment.unenrolled_at,
)
data = LearnerCreditEnterpriseCourseEnrollment(
uuid=learner_credit_course_enrollment.uuid,
created=learner_credit_course_enrollment.created,
modified=learner_credit_course_enrollment.modified,
fulfillment_type=learner_credit_course_enrollment.fulfillment_type,
enterprise_course_entitlement_uuid=(
learner_credit_course_enrollment.enterprise_course_entitlement.uuid
if learner_credit_course_enrollment.enterprise_course_entitlement
else None
),
enterprise_course_enrollment=enterprise_course_enrollment_data,
is_revoked=learner_credit_course_enrollment.is_revoked,
transaction_id=learner_credit_course_enrollment.transaction_id,
)
return data


def send_learner_credit_course_enrollment_revoked_event(learner_credit_course_enrollment):
"""
Sends the LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED openedx event.
Args:
learner_credit_course_enrollment (enterprise.models.LearnerCreditEnterpriseCourseEnrollment):
An enterprise learner credit fulfillment record that was revoked.
"""
LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED.send_event(
learner_credit_course_enrollment=serialize_learner_credit_course_enrollment(learner_credit_course_enrollment),
)
10 changes: 10 additions & 0 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
json_serialized_course_modes,
)
from enterprise.errors import LinkUserToEnterpriseError
from enterprise.event_bus import send_learner_credit_course_enrollment_revoked_event
from enterprise.logging import getEnterpriseLogger
from enterprise.tasks import send_enterprise_email_notification
from enterprise.utils import (
Expand Down Expand Up @@ -2287,6 +2288,8 @@ def revoke(self):
Marks this object as revoked and marks the associated EnterpriseCourseEnrollment
as "saved for later". This object and the associated EnterpriseCourseEnrollment are both saved.
Subclasses may override this function to additionally emit revocation events.
TODO: revoke entitlements as well?
"""
if self.enterprise_course_enrollment:
Expand Down Expand Up @@ -2330,6 +2333,13 @@ class LearnerCreditEnterpriseCourseEnrollment(EnterpriseFulfillmentSource):
.. no_pii:
"""

def revoke(self):
"""
Revoke this LearnerCreditEnterpriseCourseEnrollment, and emit a revoked event.
"""
super().revoke()
send_learner_credit_course_enrollment_revoked_event(self)

def reactivate(self, transaction_id=None, **kwargs):
"""
Idmpotently reactivates this LearnerCreditEnterpriseCourseEnrollment.
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ edx-tincan-py35
edx-toggles
jsondiff
jsonfield
openedx-events
paramiko
path.py
pillow
Expand Down
3 changes: 3 additions & 0 deletions requirements/common_constraints.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@




# A central location for most common version constraints
# (across edx repos) for pip-installation.
#
Expand Down
33 changes: 28 additions & 5 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ attrs==24.2.0
# -r requirements/test-master.txt
# -r requirements/test.txt
# aiohttp
# openedx-events
# pytest
babel==2.16.0
# via
Expand Down Expand Up @@ -221,6 +222,7 @@ django==4.2.15
# edx-rbac
# edx-toggles
# jsonfield
# openedx-events
django-cache-memoize==0.2.0
# via
# -r requirements/doc.txt
Expand Down Expand Up @@ -315,9 +317,9 @@ dnspython==2.6.1
# -r requirements/test-master.txt
# -r requirements/test.txt
# pymongo
doc8==1.1.1
doc8==1.1.2
# via -r requirements/doc.txt
docutils==0.20.1
docutils==0.21.2
# via
# -r requirements/doc.txt
# doc8
Expand Down Expand Up @@ -347,6 +349,12 @@ edx-braze-client==0.2.5
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
edx-ccx-keys==1.3.0
# via
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
# openedx-events
edx-django-utils==5.15.0
# via
# -r requirements/doc.txt
Expand All @@ -356,6 +364,7 @@ edx-django-utils==5.15.0
# edx-drf-extensions
# edx-rest-api-client
# edx-toggles
# openedx-events
edx-drf-extensions==10.3.0
# via
# -r requirements/doc.txt
Expand All @@ -371,7 +380,9 @@ edx-opaque-keys[django]==2.10.0
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
# edx-ccx-keys
# edx-drf-extensions
# openedx-events
edx-rbac==1.9.0
# via
# -r requirements/doc.txt
Expand All @@ -397,11 +408,17 @@ factory-boy==3.3.1
# -c requirements/constraints.txt
# -r requirements/doc.txt
# -r requirements/test.txt
faker==28.0.0
faker==28.4.1
# via
# -r requirements/doc.txt
# -r requirements/test.txt
# factory-boy
fastavro==1.9.5
# via
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
# openedx-events
filelock==3.15.4
# via
# -r requirements/doc.txt
Expand Down Expand Up @@ -520,6 +537,11 @@ openai==0.28.1
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
openedx-events==9.12.0
# via
# -r requirements/doc.txt
# -r requirements/test-master.txt
# -r requirements/test.txt
packaging==24.1
# via
# -r requirements/doc.txt
Expand Down Expand Up @@ -643,7 +665,7 @@ pyjwt[crypto]==2.9.0
# edx-drf-extensions
# edx-rest-api-client
# snowflake-connector-python
pylint==3.2.6
pylint==3.2.7
# via
# edx-lint
# pylint-celery
Expand Down Expand Up @@ -729,7 +751,7 @@ pyyaml==6.0.2
# drf-yasg
# edx-i18n-tools
# jsondiff
readme-renderer==43.0
readme-renderer==44.0
# via -r requirements/doc.txt
requests==2.32.3
# via
Expand Down Expand Up @@ -773,6 +795,7 @@ six==1.16.0
# -r requirements/test-master.txt
# -r requirements/test.txt
# bleach
# edx-ccx-keys
# edx-lint
# edx-rbac
# freezegun
Expand Down
24 changes: 20 additions & 4 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ attrs==24.2.0
# via
# -r requirements/test-master.txt
# aiohttp
# openedx-events
# pytest
babel==2.16.0
# via
Expand Down Expand Up @@ -138,6 +139,7 @@ django==4.2.15
# edx-rbac
# edx-toggles
# jsonfield
# openedx-events
django-cache-memoize==0.2.0
# via -r requirements/test-master.txt
django-config-models==2.7.0
Expand Down Expand Up @@ -190,9 +192,9 @@ dnspython==2.6.1
# via
# -r requirements/test-master.txt
# pymongo
doc8==1.1.1
doc8==1.1.2
# via -r requirements/doc.in
docutils==0.20.1
docutils==0.21.2
# via
# -r requirements/doc.in
# doc8
Expand All @@ -212,21 +214,28 @@ edx-api-doc-tools==1.8.0
# via -r requirements/test-master.txt
edx-braze-client==0.2.5
# via -r requirements/test-master.txt
edx-ccx-keys==1.3.0
# via
# -r requirements/test-master.txt
# openedx-events
edx-django-utils==5.15.0
# via
# -r requirements/test-master.txt
# django-config-models
# edx-drf-extensions
# edx-rest-api-client
# edx-toggles
# openedx-events
edx-drf-extensions==10.3.0
# via
# -r requirements/test-master.txt
# edx-rbac
edx-opaque-keys[django]==2.10.0
# via
# -r requirements/test-master.txt
# edx-ccx-keys
# edx-drf-extensions
# openedx-events
edx-rbac==1.9.0
# via -r requirements/test-master.txt
edx-rest-api-client==5.7.1
Expand All @@ -239,8 +248,12 @@ factory-boy==3.3.1
# via
# -c requirements/constraints.txt
# -r requirements/doc.in
faker==28.0.0
faker==28.4.1
# via factory-boy
fastavro==1.9.5
# via
# -r requirements/test-master.txt
# openedx-events
filelock==3.15.4
# via
# -r requirements/test-master.txt
Expand Down Expand Up @@ -302,6 +315,8 @@ oauthlib==3.2.2
# django-oauth-toolkit
openai==0.28.1
# via -r requirements/test-master.txt
openedx-events==9.12.0
# via -r requirements/test-master.txt
packaging==24.1
# via
# -r requirements/test-master.txt
Expand Down Expand Up @@ -409,7 +424,7 @@ pyyaml==6.0.2
# code-annotations
# drf-yasg
# jsondiff
readme-renderer==43.0
readme-renderer==44.0
# via -r requirements/doc.in
requests==2.32.3
# via
Expand All @@ -433,6 +448,7 @@ six==1.16.0
# via
# -r requirements/test-master.txt
# bleach
# edx-ccx-keys
# edx-rbac
# python-dateutil
slumber==0.7.1
Expand Down
6 changes: 3 additions & 3 deletions requirements/edx-platform-constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ edx-drf-extensions==10.3.0
# edx-when
# edxval
# openedx-learning
edx-enterprise==4.23.9
edx-enterprise==4.24.0
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/kernel.in
Expand Down Expand Up @@ -795,7 +795,7 @@ openedx-django-require==2.1.0
# via -r requirements/edx/kernel.in
openedx-django-wiki==2.1.0
# via -r requirements/edx/kernel.in
openedx-events==9.11.0
openedx-events==9.12.0
# via
# -r requirements/edx/kernel.in
# edx-event-bus-kafka
Expand All @@ -807,7 +807,7 @@ openedx-filters==1.9.0
# -r requirements/edx/kernel.in
# lti-consumer-xblock
# ora2
openedx-learning==0.11.1
openedx-learning==0.11.2
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/kernel.in
Expand Down
Loading

0 comments on commit d880ce8

Please sign in to comment.