Skip to content

Commit

Permalink
feat: [ACI-139, ACI-145] new events for badge (#4)
Browse files Browse the repository at this point in the history
* feat: [ACI-75] new public events

* feat: [ACI-139, ACI-145] new events for badge
  • Loading branch information
kyrylo-kh committed Apr 14, 2024
1 parent 3122960 commit 4ca494d
Show file tree
Hide file tree
Showing 4 changed files with 260 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"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": "template",
"type": {
"name": "BadgeTemplateData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "description",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "image_url",
"type": [
"null",
"string"
],
"default": null
}
]
}
}
]
}
}
],
"namespace": "org.openedx.learning.badge.awarded.v1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"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": "template",
"type": {
"name": "BadgeTemplateData",
"type": "record",
"fields": [
{
"name": "uuid",
"type": "string"
},
{
"name": "type",
"type": "string"
},
{
"name": "name",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "description",
"type": [
"null",
"string"
],
"default": null
},
{
"name": "image_url",
"type": [
"null",
"string"
],
"default": null
}
]
}
}
]
}
}
],
"namespace": "org.openedx.learning.badge.revoked.v1"
}
36 changes: 36 additions & 0 deletions openedx_events/learning/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,39 @@ class UserCourseData:

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


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

uuid = attr.ib(type=str)
type = attr.ib(type=str)
name = attr.ib(type=str, default=None)
description = attr.ib(type=str, default=None)
image_url = attr.ib(type=str, default=None)


@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
template (BadgeTemplateData): badge template data
"""

uuid = attr.ib(type=str)
user = attr.ib(type=UserData)
template = attr.ib(type=BadgeTemplateData)
24 changes: 24 additions & 0 deletions 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,
CourseAccessRoleData,
Expand Down Expand Up @@ -373,3 +374,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 4ca494d

Please sign in to comment.