From 03e7c7804cae29309ff479398b86330900624e0a Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Thu, 12 Dec 2024 16:33:21 +0100 Subject: [PATCH] feat: add event bus support to forum events V2 --- ...ad+response+comment+created+v2_schema.avsc | 137 ++++++++++++++++++ ...rum+thread+response+created+v2_schema.avsc | 137 ++++++++++++++++++ ...edx+learning+thread+created+v2_schema.avsc | 137 ++++++++++++++++++ openedx_events/learning/data.py | 12 ++ openedx_events/learning/signals.py | 39 +++++ 5 files changed, 462 insertions(+) create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+comment+created+v2_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+created+v2_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+thread+created+v2_schema.avsc diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+comment+created+v2_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+comment+created+v2_schema.avsc new file mode 100644 index 00000000..da0a13a6 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+comment+created+v2_schema.avsc @@ -0,0 +1,137 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "thread", + "type": { + "name": "DiscussionThreadDataV2", + "type": "record", + "fields": [ + { + "name": "anonymous", + "type": "boolean" + }, + { + "name": "anonymous_to_peers", + "type": "boolean" + }, + { + "name": "body", + "type": "string" + }, + { + "name": "category_id", + "type": "long" + }, + { + "name": "category_name", + "type": "string" + }, + { + "name": "commentable_id", + "type": "string" + }, + { + "name": "group_id", + "type": "long" + }, + { + "name": "id", + "type": "long" + }, + { + "name": "team_id", + "type": "long" + }, + { + "name": "thread_type", + "type": "string" + }, + { + "name": "title", + "type": "string" + }, + { + "name": "title_truncated", + "type": "boolean" + }, + { + "name": "truncated", + "type": "boolean" + }, + { + "name": "url", + "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": "course_id", + "type": "string" + }, + { + "name": "user_course_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "user_forums_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "discussion", + "type": "string" + }, + { + "name": "options", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.learning.forum.thread.response.comment.created.v2" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+created+v2_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+created+v2_schema.avsc new file mode 100644 index 00000000..4e05de5b --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+forum+thread+response+created+v2_schema.avsc @@ -0,0 +1,137 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "thread", + "type": { + "name": "DiscussionThreadDataV2", + "type": "record", + "fields": [ + { + "name": "anonymous", + "type": "boolean" + }, + { + "name": "anonymous_to_peers", + "type": "boolean" + }, + { + "name": "body", + "type": "string" + }, + { + "name": "category_id", + "type": "long" + }, + { + "name": "category_name", + "type": "string" + }, + { + "name": "commentable_id", + "type": "string" + }, + { + "name": "group_id", + "type": "long" + }, + { + "name": "id", + "type": "long" + }, + { + "name": "team_id", + "type": "long" + }, + { + "name": "thread_type", + "type": "string" + }, + { + "name": "title", + "type": "string" + }, + { + "name": "title_truncated", + "type": "boolean" + }, + { + "name": "truncated", + "type": "boolean" + }, + { + "name": "url", + "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": "course_id", + "type": "string" + }, + { + "name": "user_course_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "user_forums_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "discussion", + "type": "string" + }, + { + "name": "options", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.learning.forum.thread.response.created.v2" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+thread+created+v2_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+thread+created+v2_schema.avsc new file mode 100644 index 00000000..6bb4896d --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+thread+created+v2_schema.avsc @@ -0,0 +1,137 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "thread", + "type": { + "name": "DiscussionThreadDataV2", + "type": "record", + "fields": [ + { + "name": "anonymous", + "type": "boolean" + }, + { + "name": "anonymous_to_peers", + "type": "boolean" + }, + { + "name": "body", + "type": "string" + }, + { + "name": "category_id", + "type": "long" + }, + { + "name": "category_name", + "type": "string" + }, + { + "name": "commentable_id", + "type": "string" + }, + { + "name": "group_id", + "type": "long" + }, + { + "name": "id", + "type": "long" + }, + { + "name": "team_id", + "type": "long" + }, + { + "name": "thread_type", + "type": "string" + }, + { + "name": "title", + "type": "string" + }, + { + "name": "title_truncated", + "type": "boolean" + }, + { + "name": "truncated", + "type": "boolean" + }, + { + "name": "url", + "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": "course_id", + "type": "string" + }, + { + "name": "user_course_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "user_forums_roles", + "type": { + "type": "array", + "items": "string" + } + }, + { + "name": "discussion", + "type": "string" + }, + { + "name": "options", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.learning.thread.created.v2" +} \ No newline at end of file diff --git a/openedx_events/learning/data.py b/openedx_events/learning/data.py index 962dda35..5e7c1f93 100644 --- a/openedx_events/learning/data.py +++ b/openedx_events/learning/data.py @@ -428,6 +428,18 @@ class DiscussionThreadData: options = attr.ib(type=dict, factory=dict) +@attr.s(frozen=True) +class DiscussionThreadDataV2(DiscussionThreadData): + """ + Attributes defined for the Open edX to represent events in the Forum such as comments, responses, and threads. + + This class extends the DiscussionThreadData class to include support for the Open edX EVent Bus with + all serializable attributes. + """ + discussion = attr.ib(type=str, factory=str) + options = attr.ib(type=str, factory=str) + + @attr.s(frozen=True) class CourseNotificationData: """ diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py index 68fd2118..db0f8595 100644 --- a/openedx_events/learning/signals.py +++ b/openedx_events/learning/signals.py @@ -19,6 +19,7 @@ CourseNotificationData, CoursePassingStatusData, DiscussionThreadData, + DiscussionThreadDataV2, ExamAttemptData, ORASubmissionData, PersistentCourseGradeData, @@ -304,6 +305,19 @@ } ) + +# .. event_type: org.openedx.learning.forum.thread.created.v2 +# .. event_name: FORUM_THREAD_CREATED_V2 +# .. event_description: Emitted when a new thread is created in a discussion +# .. event_data: DiscussionThreadDataV2 +FORUM_THREAD_CREATED_V2 = OpenEdxPublicSignal( + event_type="org.openedx.learning.thread.created.v2", + data={ + "thread": DiscussionThreadDataV2, + } +) + + # .. event_type: org.openedx.learning.forum.thread.response.created.v1 # .. event_name: FORUM_THREAD_RESPONSE_CREATED # .. event_description: Emitted when a new response is added to a thread @@ -316,6 +330,19 @@ } ) + +# .. event_type: org.openedx.learning.forum.thread.response.created.v2 +# .. event_name: FORUM_THREAD_RESPONSE_CREATED_V2 +# .. event_description: Emitted when a new response is added to a thread +# .. event_data: DiscussionThreadData +FORUM_THREAD_RESPONSE_CREATED_V2 = OpenEdxPublicSignal( + event_type="org.openedx.learning.forum.thread.response.created.v2", + data={ + "thread": DiscussionThreadDataV2, + } +) + + # .. event_type: org.openedx.learning.forum.thread.response.comment.created.v1 # .. event_name: FORUM_RESPONSE_COMMENT_CREATED # .. event_description: Emitted when a new comment is added to a response @@ -329,6 +356,18 @@ ) +# .. event_type: org.openedx.learning.forum.thread.response.comment.created.v2 +# .. event_name: FORUM_RESPONSE_COMMENT_CREATED_V2 +# .. event_description: Emitted when a new comment is added to a response +# .. event_data: DiscussionThreadData +FORUM_RESPONSE_COMMENT_CREATED_V2 = OpenEdxPublicSignal( + event_type="org.openedx.learning.forum.thread.response.comment.created.v2", + data={ + "thread": DiscussionThreadDataV2, + } +) + + # .. event_type: org.openedx.learning.course.notification.requested.v1 # .. event_name: COURSE_NOTIFICATION_REQUESTED # .. event_description: Emitted when a notification is requested for a course