From 7e6e92429485133bf16ae4494da71b5a2ac31b9e Mon Sep 17 00:00:00 2001 From: Isaac Lee <124631592+ilee2u@users.noreply.github.com> Date: Mon, 2 Oct 2023 14:34:42 -0400 Subject: [PATCH] feat: add/remove manage students permission events (#267) --- CHANGELOG.rst | 8 +++- ...12-producing-to-event-bus-via-settings.rst | 2 +- ...cial-exam-submission-and-review-events.rst | 2 +- openedx_events/__init__.py | 2 +- ...+students+permission+added+v1_schema.avsc} | 28 +++++++++--- ...tudents+permission+removed+v1_schema.avsc} | 28 +++++++++--- openedx_events/learning/data.py | 43 +++++++++++++++++++ openedx_events/learning/signals.py | 23 ++++++++++ 8 files changed, 120 insertions(+), 16 deletions(-) rename openedx_events/event_bus/avro/tests/schemas/{org+openedx+learning+user+course+staff+role+added+v1_schema.avsc => org+openedx+learning+user+manage+students+permission+added+v1_schema.avsc} (75%) rename openedx_events/event_bus/avro/tests/schemas/{org+openedx+learning+user+course+staff+role+removed+v1_schema.avsc => org+openedx+learning+user+manage+students+permission+removed+v1_schema.avsc} (75%) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c68c76b3..6abeece9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,11 +17,17 @@ Changed ~~~~~~~ * Re-licensed this repository from AGPL 3.0 to Apache 2.0 +[8.8.0] - 2023-10-02 +-------------------- +Added +~~~~~ +* Added new ``MANAGE_STUDENTS_PERMISSION_ADDED`` and ``MANAGE_STUDENTS_PERMISSION_REMOVED`` events in learning + [8.7.0] - 2023-09-29 -------------------- Added ~~~~~ -* Added new ``EXAM_ATTEMPT_SUBMITTED``, ``EXAM_ATTEMPT_REJECTED``, ``EXAM_ATTEMPT_VERIFIED``, ``EXAM_ATTEMPT_RESET``, and ``EXAM_ATTEMPT_ERRORED`` in learning. +* Added new ``EXAM_ATTEMPT_SUBMITTED``, ``EXAM_ATTEMPT_REJECTED``, ``EXAM_ATTEMPT_VERIFIED``, ``EXAM_ATTEMPT_RESET``, and ``EXAM_ATTEMPT_ERRORED`` events in learning. [8.6.0] - 2023-08-28 -------------------- diff --git a/docs/decisions/0012-producing-to-event-bus-via-settings.rst b/docs/decisions/0012-producing-to-event-bus-via-settings.rst index aa5c00c2..a9fe834e 100644 --- a/docs/decisions/0012-producing-to-event-bus-via-settings.rst +++ b/docs/decisions/0012-producing-to-event-bus-via-settings.rst @@ -1,4 +1,4 @@ -11. Enable producing to event bus via settings +12. Enable producing to event bus via settings ############################################## Status diff --git a/docs/decisions/0013-special-exam-submission-and-review-events.rst b/docs/decisions/0013-special-exam-submission-and-review-events.rst index aa6f9ae0..3cdd84a1 100644 --- a/docs/decisions/0013-special-exam-submission-and-review-events.rst +++ b/docs/decisions/0013-special-exam-submission-and-review-events.rst @@ -1,4 +1,4 @@ -12. Event definitions for special exam post-submission and review +13. Event definitions for special exam post-submission and review ################################################################# Status diff --git a/openedx_events/__init__.py b/openedx_events/__init__.py index e2ea442e..ce209e12 100644 --- a/openedx_events/__init__.py +++ b/openedx_events/__init__.py @@ -5,4 +5,4 @@ more information about the project. """ -__version__ = "8.7.0" +__version__ = "8.8.0" diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+added+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+added+v1_schema.avsc similarity index 75% rename from openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+added+v1_schema.avsc rename to openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+added+v1_schema.avsc index b683d683..33ff3d5d 100644 --- a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+added+v1_schema.avsc +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+added+v1_schema.avsc @@ -6,13 +6,9 @@ { "name": "course_staff_data", "type": { - "name": "CourseStaffData", + "name": "ManageStudentsPermissionData", "type": "record", "fields": [ - { - "name": "course_key", - "type": "string" - }, { "name": "user", "type": { @@ -50,10 +46,30 @@ } ] } + }, + { + "name": "permission", + "type": "string" + }, + { + "name": "course_key", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "org", + "type": [ + "null", + "string" + ], + "default": null } ] } } ], - "namespace": "org.openedx.learning.user.course.staff.role.added.v1" + "namespace": "org.openedx.learning.user.manage.students.permission.added.v1" } \ No newline at end of file diff --git a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+removed+v1_schema.avsc b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+removed+v1_schema.avsc similarity index 75% rename from openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+removed+v1_schema.avsc rename to openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+removed+v1_schema.avsc index 6b6f9dfa..99224a26 100644 --- a/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+course+staff+role+removed+v1_schema.avsc +++ b/openedx_events/event_bus/avro/tests/schemas/org+openedx+learning+user+manage+students+permission+removed+v1_schema.avsc @@ -6,13 +6,9 @@ { "name": "course_staff_data", "type": { - "name": "CourseStaffData", + "name": "ManageStudentsPermissionData", "type": "record", "fields": [ - { - "name": "course_key", - "type": "string" - }, { "name": "user", "type": { @@ -50,10 +46,30 @@ } ] } + }, + { + "name": "permission", + "type": "string" + }, + { + "name": "course_key", + "type": [ + "null", + "string" + ], + "default": null + }, + { + "name": "org", + "type": [ + "null", + "string" + ], + "default": null } ] } } ], - "namespace": "org.openedx.learning.user.course.staff.role.removed.v1" + "namespace": "org.openedx.learning.user.manage.students.permission.removed.v1" } \ No newline at end of file diff --git a/openedx_events/learning/data.py b/openedx_events/learning/data.py index b4189f08..ba07d871 100644 --- a/openedx_events/learning/data.py +++ b/openedx_events/learning/data.py @@ -329,3 +329,46 @@ class ExamAttemptData: usage_key = attr.ib(type=UsageKey) exam_type = attr.ib(type=str) requesting_user = attr.ib(type=UserData, default=None) + + +@attr.s(frozen=True) +class ManageStudentsPermissionData: + """ + Attributes defined for the Open edX to represent users that can manage students within a course/org. + + IMPORTANT: + edX currently uses roles, and only roles, to decide what kind of access a user has. + + There is an ongoing project to replace this roles-only system with a system that uses roles that are + made up of permissions, which is being worked on in parallel with another project to emit events + whenever users are assigned any type of "Course Staff" role. + + It's unclear what the state of this roles/permissions project will be the time the events project + is completed, so each project's respective teams will stay in touch with each other. + + For now, we're making a best effort to publish this an event that will regard the permission(s) + we'd expect to "filter" for in the future (For more info, please check out this document: + https://docs.google.com/spreadsheets/d/1htsV0eWq5-y96DZ5A245ukfZ4_qeH0KjHVaOyfqD8OA/edit#gid=908503896) + and not for the roles we have now. Likely this/these permission(s) will be something like `manage_students`, + but we need to evaluate how this will align with some possible future roles such as `limited_staff` or `ccx`. + + As such, the current plan is to do one of the following once the roles/permissions project's + feature branch is merged to master: + 1. Modify this event to "filter" by the correct permissions once the + 2. As a backup plan, make a new event if this proves too difficult. + + Until either of these plans are executed, this comment under the IMPORTANT header should stay put. + + Arguments: + user (UserData): User who will have a role/permission assigned/removed. + permission (str): The permission the user is being assigned. + course_key (Course ID): identifier of the course where the user will have staff role assigned/removed. + A blank course_id implies org wide role. + org (str): identifier of the org where the user will have staff role assigned/removed. + A blank org is for global group based roles such as course creator (may be deprecated). + """ + + user = attr.ib(type=UserData) + permission = attr.ib(type=str) + course_key = attr.ib(type=str, default=None) + org = attr.ib(type=str, default=None) diff --git a/openedx_events/learning/signals.py b/openedx_events/learning/signals.py index ece24cf9..81ace1c7 100644 --- a/openedx_events/learning/signals.py +++ b/openedx_events/learning/signals.py @@ -14,6 +14,7 @@ CourseDiscussionConfigurationData, CourseEnrollmentData, ExamAttemptData, + ManageStudentsPermissionData, PersistentCourseGradeData, ProgramCertificateData, UserData, @@ -252,3 +253,25 @@ "exam_attempt": ExamAttemptData, } ) + +# .. 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. +# .. event_data: ManageStudentsPermissionData +MANAGE_STUDENTS_PERMISSION_ADDED = OpenEdxPublicSignal( + event_type="org.openedx.learning.user.manage.students.permission.added.v1", + data={ + "course_staff_data": ManageStudentsPermissionData, + } +) + +# .. event_type: org.openedx.learning.user.manage.students.permission.removed.v1 +# .. event_name: MANAGE_STUDENTS_PERMISSION_REMOVED +# .. event_description: Emitted when permission to manage students within a course is removed from a user. +# .. event_data: ManageStudentsPermissionData +MANAGE_STUDENTS_PERMISSION_REMOVED = OpenEdxPublicSignal( + event_type="org.openedx.learning.user.manage.students.permission.removed.v1", + data={ + "course_staff_data": ManageStudentsPermissionData, + } +)