Skip to content

Commit

Permalink
feat: [ACI-139, ACI-145] new events for badge
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh committed Jan 12, 2024
1 parent f6bb383 commit 69e0da9
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "badge",
"type": {
"name": "BadgeData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "user",
"type": {
"name": "UserData",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "is_active",
"type": "boolean"
},
{
"name": "pii",
"type": {
"name": "UserPersonalData",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "name",
"type": "string"
}
]
}
}
]
}
},
{
"name": "badge_type",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "description",
"type": "string"
},
{
"name": "image_url",
"type": "string"
}
]
}
}
],
"namespace": "org.openedx.learning.badge.awarded.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"name": "CloudEvent",
"type": "record",
"doc": "Avro Event Format for CloudEvents created with openedx_events/schema",
"fields": [
{
"name": "badge",
"type": {
"name": "BadgeData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "user",
"type": {
"name": "UserData",
"type": "record",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "is_active",
"type": "boolean"
},
{
"name": "pii",
"type": {
"name": "UserPersonalData",
"type": "record",
"fields": [
{
"name": "username",
"type": "string"
},
{
"name": "email",
"type": "string"
},
{
"name": "name",
"type": "string"
}
]
}
}
]
}
},
{
"name": "badge_type",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "description",
"type": "string"
},
{
"name": "image_url",
"type": "string"
}
]
}
}
],
"namespace": "org.openedx.learning.badge.revoked.v1"
}
22 changes: 22 additions & 0 deletions openedx_events/learning/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,25 @@ class UserCourseData:

user = attr.ib(type=UserData)
course = attr.ib(type=CourseData)


@attr.s(frozen=True)
class BadgeData:
"""
Attributes defined for the Open edX badge data object.
Arguments:
uuid (str): the UUID of the badge
user (UserData): user associated with the badge
badge_type (str): type of badge
name (str): badge name
description (str): badge description
image_url (str): badge image url
"""

uuid = attr.ib(type=str)
user = attr.ib(type=UserData)
badge_type = attr.ib(type=str)
name = attr.ib(type=str)
description = attr.ib(type=str)
image_url = attr.ib(type=str)
25 changes: 24 additions & 1 deletion openedx_events/learning/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from openedx_events.learning.data import (
BadgeData,
CertificateData,
CohortData,
CourseDiscussionConfigurationData,
Expand All @@ -23,7 +24,6 @@
UserData,
UserNotificationData,
XBlockSkillVerificationData,
UserCourseData,
)
from openedx_events.tooling import OpenEdxPublicSignal

Expand Down Expand Up @@ -351,3 +351,26 @@
"user_course_data": UserCourseData,
}
)

# .. event_type: org.openedx.learning.badge.awarded.v1
# .. event_name: BADGE_AWARDED
# .. event_description: Emit when a badge is awarded to a learner
# .. event_data: BadgeData
BADGE_AWARDED = OpenEdxPublicSignal(
event_type="org.openedx.learning.badge.awarded.v1",
data={
"badge": BadgeData,
}
)


# .. event_type: org.openedx.learning.badge.revoked.v1
# .. event_name: BADGE_REVOKED
# .. event_description: Emit when a badge is revoked for a learner
# .. event_data: BadgeData
BADGE_REVOKED = OpenEdxPublicSignal(
event_type="org.openedx.learning.badge.revoked.v1",
data={
"badge": BadgeData,
}
)

0 comments on commit 69e0da9

Please sign in to comment.