From 2b4563fd72e19502accb17f8b00a7e4be610eefa Mon Sep 17 00:00:00 2001
From: Kyrylo Kholodenko <kyrylo.kholodenko@raccoongang.com>
Date: Thu, 14 Dec 2023 00:34:18 +0200
Subject: [PATCH] feat: [ACI-75] new public events

---
 ...ing+course+grade+now+failed+v1_schema.avsc | 88 +++++++++++++++++++
 ...ing+course+grade+now+passed+v1_schema.avsc | 88 +++++++++++++++++++
 openedx_events/learning/data.py               | 14 +++
 openedx_events/learning/signals.py            | 23 +++++
 4 files changed, 213 insertions(+)
 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/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 39bfb24f..0e713650 100644
--- a/openedx_events/learning/data.py
+++ b/openedx_events/learning/data.py
@@ -469,3 +469,17 @@ class CourseNotificationData:
     content_url = attr.ib(type=str)
     content_context = attr.ib(type=dict, factory=dict)
     audience_filters = attr.ib(type=dict, factory=dict)
+
+
+@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)
diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py
index 9ec57e0b..b42f2979 100644
--- a/openedx_events/learning/signals.py
+++ b/openedx_events/learning/signals.py
@@ -19,6 +19,7 @@
     ManageStudentsPermissionData,
     PersistentCourseGradeData,
     ProgramCertificateData,
+    UserCourseData,
     UserData,
     UserNotificationData,
     XBlockSkillVerificationData,
@@ -327,3 +328,25 @@
         "course_notification_data": CourseNotificationData,
     }
 )
+
+# .. 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,
+    }
+)