Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add courseaccessrole events #309

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------
Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "9.3.0"
__version__ = "9.4.0"
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions openedx_events/learning/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ class ExamAttemptData:
requesting_user = attr.ib(type=UserData, default=None)


@attr.s(frozen=True)
class CourseAccessRoleData:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the ManageStudentsPermissionData class defined below makes me wonder if we should refrain from using the word "role" in this class name. I know you've talked to more people about the roles + permissions work though, so I trust your judgement!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. Yup the conclusion we came to was to define this as edx-platform exists today rather than trying to guess the future. I kept the name specific to the LMS model so it's use is clear instead of a ambiguous half-measure that might be reusable in the future.

There's no longer a near term path to the permission changes getting merged as we had originally wanted to account for. I'm not sure manage students will even end up being the correct permission when that the time does come to use permissions over roles.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, appreciate the explanation! This looks good then 👍

"""
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:
"""
Expand Down
23 changes: 23 additions & 0 deletions openedx_events/learning/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from openedx_events.learning.data import (
CertificateData,
CohortData,
CourseAccessRoleData,
CourseDiscussionConfigurationData,
CourseEnrollmentData,
CourseNotificationData,
Expand Down Expand Up @@ -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.
Expand Down