From 5d340fdc7c31c4c94d9c6838d617119d31a2fef0 Mon Sep 17 00:00:00 2001 From: Zachary Hancock Date: Thu, 1 Feb 2024 09:20:10 -0500 Subject: [PATCH] feat: add courseaccessrole events (#309) --- CHANGELOG.rst | 5 ++ openedx_events/__init__.py | 2 +- ...er+course_access_role+added+v1_schema.avsc | 67 +++++++++++++++++++ ...+course_access_role+removed+v1_schema.avsc | 67 +++++++++++++++++++ openedx_events/learning/data.py | 18 +++++ openedx_events/learning/signals.py | 23 +++++++ 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+added+v1_schema.avsc create mode 100644 openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+removed+v1_schema.avsc diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b620219e..639217b9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Change Log Unreleased ---------- +[9.4.0] - 2024-01-29 +-------------------- +Added +~~~~~ +* Added new ``COURSE_ACCESS_ROLE_ADDED`` and ``COURSE_ACCESS_ROLE_REMOVED`` events in learning [9.3.0] - 2024-01-24 -------------------- diff --git a/openedx_events/__init__.py b/openedx_events/__init__.py index bb45b9cd..35cdf1da 100644 --- a/openedx_events/__init__.py +++ b/openedx_events/__init__.py @@ -5,4 +5,4 @@ more information about the project. """ -__version__ = "9.3.0" +__version__ = "9.4.0" diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+added+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+added+v1_schema.avsc new file mode 100644 index 00000000..0c134b86 --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+added+v1_schema.avsc @@ -0,0 +1,67 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "course_access_role_data", + "type": { + "name": "CourseAccessRoleData", + "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": "org_key", + "type": "string" + }, + { + "name": "course_key", + "type": "string" + }, + { + "name": "role", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.learning.user.course_access_role.added.v1" +} \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+removed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+removed+v1_schema.avsc new file mode 100644 index 00000000..fa064ebf --- /dev/null +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course_access_role+removed+v1_schema.avsc @@ -0,0 +1,67 @@ +{ + "name": "CloudEvent", + "type": "record", + "doc": "Avro Event Format for CloudEvents created with openedx_events/schema", + "fields": [ + { + "name": "course_access_role_data", + "type": { + "name": "CourseAccessRoleData", + "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": "org_key", + "type": "string" + }, + { + "name": "course_key", + "type": "string" + }, + { + "name": "role", + "type": "string" + } + ] + } + } + ], + "namespace": "org.openedx.learning.user.course_access_role.removed.v1" +} \ No newline at end of file diff --git a/openedx_events/learning/data.py b/openedx_events/learning/data.py index 39bfb24f..e8c6bc2f 100644 --- a/openedx_events/learning/data.py +++ b/openedx_events/learning/data.py @@ -331,6 +331,24 @@ class ExamAttemptData: requesting_user = attr.ib(type=UserData, default=None) +@attr.s(frozen=True) +class CourseAccessRoleData: + """ + Attributes defined for the Open edX Course Access Role data object. + + Arguments: + user (UserData): user associated with the CourseAccessRole. + course_key (CourseKey): identifer of the related course object. + org (str): identifier of the organization. + role (str): the role of the user in the course. + """ + + user = attr.ib(type=UserData) + org_key = attr.ib(type=str) + course_key = attr.ib(type=CourseKey) + role = attr.ib(type=str) + + @attr.s(frozen=True) class ManageStudentsPermissionData: """ diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py index 9ec57e0b..ed36fab4 100644 --- a/openedx_events/learning/signals.py +++ b/openedx_events/learning/signals.py @@ -11,6 +11,7 @@ from openedx_events.learning.data import ( CertificateData, CohortData, + CourseAccessRoleData, CourseDiscussionConfigurationData, CourseEnrollmentData, CourseNotificationData, @@ -256,6 +257,28 @@ } ) +# .. event_type: org.openedx.learning.user.course_access_role.added.v1 +# .. event_name: COURSE_ACCESS_ROLE_ADDED +# .. event_description: Emitted when a user is given a course access role. +# .. event_data: CourseAccessRoleData +COURSE_ACCESS_ROLE_ADDED = OpenEdxPublicSignal( + event_type="org.openedx.learning.user.course_access_role.added.v1", + data={ + "course_access_role_data": CourseAccessRoleData, + } +) + +# .. event_type: org.openedx.learning.user.course_access_role.removed.v1 +# .. event_name: COURSE_ACCESS_ROLE_REMOVED +# .. event_description: Emitted when a course access role is removed from a user. +# .. event_data: CourseAccessRoleData +COURSE_ACCESS_ROLE_REMOVED = OpenEdxPublicSignal( + event_type="org.openedx.learning.user.course_access_role.removed.v1", + data={ + "course_access_role_data": CourseAccessRoleData, + } +) + # .. event_type: org.openedx.learning.user.manage.students.permission.added.v1 # .. event_name: MANAGE_STUDENTS_PERMISSION_ADDED # .. event_description: Emitted when permission to manage students within a course is given to a user.