From 4b67a5701f77787b975f2185f546b717ffbe2eef Mon Sep 17 00:00:00 2001 From: Kyrylo Kholodenko Date: Mon, 22 Jan 2024 15:32:09 +0200 Subject: [PATCH] feat: add new learning events for course grades and badges --- CHANGELOG.rst | 5 + openedx_events/__init__.py | 2 +- ...nedx+learning+badge+awarded+v1_schema.avsc | 100 ++++++++++++++++++ ...nedx+learning+badge+revoked+v1_schema.avsc | 100 ++++++++++++++++++ ...ing+course+grade+now+failed+v1_schema.avsc | 88 +++++++++++++++ ...ing+course+grade+now+passed+v1_schema.avsc | 88 +++++++++++++++ openedx_events/learning/data.py | 50 +++++++++ openedx_events/learning/signals.py | 47 ++++++++ 8 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+awarded+v1_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+revoked+v1_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+failed+v1_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+passed+v1_schema.avsc diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fb7471db..cfc30a35 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Change Log Unreleased ---------- +[9.10.0] - 2024-04-12 +-------------------- +Added +~~~~~~~ +* Added new COURSE_GRADE_NOW_PASSED, COURSE_GRADE_NOW_FAILED, BADGE_AWARDED, BADGE_REVOKED events in learning [9.9.1] - 2024-04-12 -------------------- diff --git a/openedx_events/__init__.py b/openedx_events/__init__.py index 7dc0578d..6eb6186c 100644 --- a/openedx_events/__init__.py +++ b/openedx_events/__init__.py @@ -5,4 +5,4 @@ more information about the project. """ -__version__ = "9.9.1" +__version__ = "9.10.0" diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+awarded+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+awarded+v1_schema.avsc new file mode 100644 index 00000000..5e374a35 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+awarded+v1_schema.avsc @@ -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" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+revoked+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+revoked+v1_schema.avsc new file mode 100644 index 00000000..eade1a70 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+badge+revoked+v1_schema.avsc @@ -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" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+failed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+failed+v1_schema.avsc new file mode 100644 index 00000000..ade981c8 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+failed+v1_schema.avsc @@ -0,0 +1,88 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "user_course_data", + "type": { + "name": "UserCourseData", + "type": "record", + "fields": [ + { + "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": "course", + "type": { + "name": "CourseData", + "type": "record", + "fields": [ + { + "name": "course_key", + "type": "string" + }, + { + "name": "display_name", + "type": "string" + }, + { + "name": "start", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "end", + "type": [ + "null", + "string" + ], + "default": null + } + ] + } + } + ] + } + } + ], + "namespace": "org.openedx.learning.course.grade.now.failed.v1" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+passed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+passed+v1_schema.avsc new file mode 100644 index 00000000..19534cab --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+course+grade+now+passed+v1_schema.avsc @@ -0,0 +1,88 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "user_course_data", + "type": { + "name": "UserCourseData", + "type": "record", + "fields": [ + { + "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": "course", + "type": { + "name": "CourseData", + "type": "record", + "fields": [ + { + "name": "course_key", + "type": "string" + }, + { + "name": "display_name", + "type": "string" + }, + { + "name": "start", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "end", + "type": [ + "null", + "string" + ], + "default": null + } + ] + } + } + ] + } + } + ], + "namespace": "org.openedx.learning.course.grade.now.passed.v1" +} \ No newline at end of file diff --git a/openedx_events/learning/data.py b/openedx_events/learning/data.py index 2aa03baf..dcbf663f 100644 --- a/openedx_events/learning/data.py +++ b/openedx_events/learning/data.py @@ -476,3 +476,53 @@ class ORASubmissionData: id = attr.ib(type=str) file_downloads = attr.ib(type=List[ORAFileDownloadsData], factory=list) + + +@attr.s(frozen=True) +class UserCourseData: + """ + Attributes defined for Open edX user course data object. + + Arguments: + user (UserData): user associated with the Course Enrollment. + course (CourseData): course where the user is enrolled in. + """ + + 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) diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py index 9459d891..b188c226 100644 --- a/openedx_events/learning/signals.py +++ b/openedx_events/learning/signals.py @@ -9,6 +9,7 @@ """ from openedx_events.learning.data import ( + BadgeData, CertificateData, CohortData, CourseAccessRoleData, @@ -20,6 +21,7 @@ ORASubmissionData, PersistentCourseGradeData, ProgramCertificateData, + UserCourseData, UserData, UserNotificationData, XBlockSkillVerificationData, @@ -350,3 +352,48 @@ "submission": ORASubmissionData, }, ) + +# .. event_type: org.openedx.learning.course.grade.now.passed.v1 +# .. event_name: COURSE_GRADE_NOW_PASSED +# .. event_description: Emmited when course grade is passed. +# .. event_data: UserCourseData +COURSE_GRADE_NOW_PASSED = OpenEdxPublicSignal( + event_type="org.openedx.learning.course.grade.now.passed.v1", + data={ + "user_course_data": UserCourseData, + } +) + +# .. event_type: org.openedx.learning.course.grade.now.failed.v1 +# .. event_name: COURSE_GRADE_NOW_FAILED +# .. event_description: Emmited when course grade is failed. +# .. event_data: UserCourseData +COURSE_GRADE_NOW_FAILED = OpenEdxPublicSignal( + event_type="org.openedx.learning.course.grade.now.failed.v1", + data={ + "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, + } +)