Skip to content

Commit

Permalink
feat: Add enterprise signal for learner credit fulfillment revokation
Browse files Browse the repository at this point in the history
ENT-9213
  • Loading branch information
pwnage101 committed Jul 31, 2024
1 parent 238186a commit 64c472b
Show file tree
Hide file tree
Showing 3 changed files with 213 additions and 1 deletion.
64 changes: 64 additions & 0 deletions openedx_events/enterprise/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,67 @@ class LedgerTransaction(BaseLedgerTransaction):
parent_content_key = attr.ib(type=str, default=None)
fulfillment_identifier = attr.ib(type=str, default=None)
reversal = attr.ib(type=LedgerTransactionReversal, default=None)


@attr.s(frozen=True)
class EnterpriseCustomerUser:
"""
Defines the common attributes of enterprise fulfillment classes.
"""
id = attr.ib(type=int)
created = attr.ib(type=datetime)
modified = attr.ib(type=datetime)
enterprise_customer_uuid = attr.ib(type=UUID)
user_id = attr.ib(type=int)
active = attr.ib(type=bool)
linked = attr.ib(type=bool)
is_relinkable = attr.ib(type=bool)
invite_key = attr.ib(type=UUID)
should_inactivate_other_customers = attr.ib(type=bool)


@attr.s(frozen=True)
class EnterpriseCourseEnrollment:
"""
Defines the common attributes of enterprise fulfillment classes.
"""
id = attr.ib(type=int)
created = attr.ib(type=datetime)
modified = attr.ib(type=datetime)
enterprise_customer_user = attr.ib(type=EnterpriseCustomerUser)
course_id = attr.ib(type=CourseKey)
saved_for_later = attr.ib(type=bool)
source_slug = attr.ib(type=str)
unenrolled = attr.ib(type=bool)
unenrolled_at = attr.ib(type=datetime)


@attr.s(frozen=True)
class BaseEnterpriseFulfillment:
"""
Defines the common attributes of enterprise fulfillment classes, i.e. attributes of an
``enterprise.EnterpriseFulfillmentSource`` record.
"""
uuid = attr.ib(type=UUID)
created = attr.ib(type=datetime)
modified = attr.ib(type=datetime)
fulfillment_type = attr.ib(type=str)
enterprise_course_entitlement_uuid = attr.ib(type=UUID)
enterprise_course_enrollment = attr.ib(type=EnterpriseCourseEnrollment)
is_revoked = attr.ib(type=bool)


@attr.s(frozen=True)
class LearnerCreditEnterpriseCourseEnrollment(BaseEnterpriseFulfillment):
"""
Attributes of an ``enterprise.LearnerCreditEnterpriseCourseEnrollment`` record.
"""
transaction_id = attr.ib(type=UUID)


@attr.s(frozen=True)
class LicensedEnterpriseCourseEnrollment(BaseEnterpriseFulfillment):
"""
Attributes of an ``enterprise.LicensedEnterpriseCourseEnrollment`` record.
"""
license_uuid = attr.ib(type=UUID)
15 changes: 14 additions & 1 deletion openedx_events/enterprise/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
docs/decisions/0003-events-payload.rst
"""

from openedx_events.enterprise.data import LedgerTransaction, SubsidyRedemption
from openedx_events.enterprise.data import LearnerCreditEnterpriseCourseEnrollment, LedgerTransaction, SubsidyRedemption
from openedx_events.tooling import OpenEdxPublicSignal

# .. event_type: org.openedx.enterprise.subsidy.redeemed.v1
Expand Down Expand Up @@ -84,3 +84,16 @@
"ledger_transaction": LedgerTransaction,
}
)


# .. event_type: org.openedx.enterprise.learner_credit_course_enrollment.revoked.v1
# .. event_name: LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED
# .. event_description: emitted when a LearnerCreditEnterpriseCourseEnrollment is revoked. This most often happens when
# an enterprise learner unenrolls from a course which was LC-subsidized.
# .. event_data: LearnerCreditEnterpriseCourseEnrollment
LEARNER_CREDIT_COURSE_ENROLLMENT_REVOKED = OpenEdxPublicSignal(
event_type="org.openedx.enterprise.learner_credit_course_enrollment.revoked.v1",
data={
"learner_credit_course_enrollment": LearnerCreditEnterpriseCourseEnrollment,
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "learner_credit_course_enrollment",
"type": {
"name": "LearnerCreditEnterpriseCourseEnrollment",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "created",
"type": "string"
},
{
"name": "modified",
"type": "string"
},
{
"name": "fulfillment_type",
"type": "string"
},
{
"name": "enterprise_course_entitlement_uuid",
"type": "string"
},
{
"name": "enterprise_course_enrollment",
"type": {
"name": "EnterpriseCourseEnrollment",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "created",
"type": "string"
},
{
"name": "modified",
"type": "string"
},
{
"name": "enterprise_customer_user",
"type": {
"name": "EnterpriseCustomerUser",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "created",
"type": "string"
},
{
"name": "modified",
"type": "string"
},
{
"name": "enterprise_customer_uuid",
"type": "string"
},
{
"name": "user_id",
"type": "long"
},
{
"name": "active",
"type": "boolean"
},
{
"name": "linked",
"type": "boolean"
},
{
"name": "is_relinkable",
"type": "boolean"
},
{
"name": "invite_key",
"type": "string"
},
{
"name": "should_inactivate_other_customers",
"type": "boolean"
}
]
}
},
{
"name": "course_id",
"type": "string"
},
{
"name": "saved_for_later",
"type": "boolean"
},
{
"name": "source_slug",
"type": "string"
},
{
"name": "unenrolled",
"type": "boolean"
},
{
"name": "unenrolled_at",
"type": "string"
}
]
}
},
{
"name": "is_revoked",
"type": "boolean"
},
{
"name": "transaction_id",
"type": "string"
}
]
}
}
],
"namespace": "org.openedx.enterprise.learner_credit_course_enrollment.revoked.v1"
}

0 comments on commit 64c472b

Please sign in to comment.