From ca463458bbac10edd446e25aec386c2394a90df4 Mon Sep 17 00:00:00 2001 From: andrii-hantkovskyi <131773947+andrii-hantkovskyi@users.noreply.github.com> Date: Tue, 26 Mar 2024 15:20:59 +0200 Subject: [PATCH] feat: [ACI-510, ACI-511, ACI-512] new events and dataclass for ccx course (#5) * feat: [ACI-512] describe ccx course payload dataclass * feat: [ACI-510] define ccx-course-grade-passed signal * feat: [ACI-511] define ccx-course-grade-failed signal * feat: [ACI-510, ACI-511, ACI-512] new events and dataclass for ccx course * style: [ACI-512] fix line-too-long and trailing-whitespace --------- Co-authored-by: Andrii --- ...ccx+course+grade+now+failed+v1_schema.avsc | 87 +++++++++++++++++++ ...ccx+course+grade+now+passed+v1_schema.avsc | 87 +++++++++++++++++++ openedx_events/learning/data.py | 21 +++++ openedx_events/learning/signals.py | 25 ++++++ 4 files changed, 220 insertions(+) create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+failed+v1_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+passed+v1_schema.avsc diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+failed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+failed+v1_schema.avsc new file mode 100644 index 00000000..1b6c4ad3 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+failed+v1_schema.avsc @@ -0,0 +1,87 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "ccx_course", + "type": { + "name": "CcxCourseData", + "type": "record", + "fields": [ + { + "name": "course_key", + "type": "string" + }, + { + "name": "master_course_key", + "type": "string" + }, + { + "name": "max_students_allowed", + "type": "long" + }, + { + "name": "coach", + "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": "display_name", + "type": "string" + }, + { + "name": "start", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "end", + "type": [ + "null", + "string" + ], + "default": null + } + ] + } + } + ], + "namespace": "org.openedx.learning.ccx.course.grade.now.failed.v1" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+passed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+passed+v1_schema.avsc new file mode 100644 index 00000000..7bf247d6 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+ccx+course+grade+now+passed+v1_schema.avsc @@ -0,0 +1,87 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "ccx_course", + "type": { + "name": "CcxCourseData", + "type": "record", + "fields": [ + { + "name": "course_key", + "type": "string" + }, + { + "name": "master_course_key", + "type": "string" + }, + { + "name": "max_students_allowed", + "type": "long" + }, + { + "name": "coach", + "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": "display_name", + "type": "string" + }, + { + "name": "start", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "end", + "type": [ + "null", + "string" + ], + "default": null + } + ] + } + } + ], + "namespace": "org.openedx.learning.ccx.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 fdca01d3..b8729d72 100644 --- a/openedx_events/learning/data.py +++ b/openedx_events/learning/data.py @@ -494,3 +494,24 @@ class BadgeData: uuid = attr.ib(type=str) user = attr.ib(type=UserData) template = attr.ib(type=BadgeTemplateData) + + +@attr.s(frozen=True) +class CcxCourseData(CourseData): + """ + Attributes defined fir the Open edX custom course data object. + + Arguments: + master_course_key (str): identifier of the master Course object. + max_students_allowed (int): maximum number of students allowed on the custom course + coach (UserData): coach associated with the custom course + """ + + master_course_key = attr.ib(type=CourseKey) + max_students_allowed = attr.ib(type=int) + coach = attr.ib(type=UserData) + + # copypasted from CourseData to avoid ValueError + display_name = attr.ib(type=str, factory=str) + start = attr.ib(type=datetime, default=None) + end = attr.ib(type=datetime, default=None) diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py index 99af1924..1ee21173 100644 --- a/openedx_events/learning/signals.py +++ b/openedx_events/learning/signals.py @@ -10,6 +10,7 @@ from openedx_events.learning.data import ( BadgeData, + CcxCourseData, CertificateData, CohortData, CourseAccessRoleData, @@ -383,3 +384,27 @@ "badge": BadgeData, } ) + + +# .. event_type: org.openedx.learning.ccx.course.grade.now.passed.v1 +# .. event_name: CCX_COURSE_GRADE_NOW_PASSED +# .. event_description: Emit when a ccx course grade is passed +# .. event_data: CcxCourseData +CCX_COURSE_GRADE_NOW_PASSED = OpenEdxPublicSignal( + event_type="org.openedx.learning.ccx.course.grade.now.passed.v1", + data={ + "ccx_course": CcxCourseData, + } +) + + +# .. event_type: org.openedx.learning.ccx.course.grade.now.failed.v1 +# .. event_name: CCX_COURSE_GRADE_NOW_FAILED +# .. event_description: Emit when a ccx course grade is failed +# .. event_data: CcxCourseData +CCX_COURSE_GRADE_NOW_FAILED = OpenEdxPublicSignal( + event_type="org.openedx.learning.ccx.course.grade.now.failed.v1", + data={ + "ccx_course": CcxCourseData, + } +)