Skip to content

Commit

Permalink
feat: add new COURSE_NOTIFICATION_REQUESTED event for notifications w…
Browse files Browse the repository at this point in the history
…ith wider audience (#285)

Co-authored-by: SaadYousaf <saadyousaf@A006-00314.local>
  • Loading branch information
saadyousafarbi and SaadYousaf authored Nov 16, 2023
1 parent 39f1f67 commit 1a5f9ca
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Change Log
Unreleased
----------

[9.2.0] - 2023-11-16
--------------------
Added
~~~~~~~
* Added new COURSE_NOTIFICATION_REQUESTED event in learning

[9.1.0] - 2023-11-07
--------------------
Added
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.1.0"
__version__ = "9.2.0"
50 changes: 47 additions & 3 deletions openedx_events/learning/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ class UserNotificationData:
Attributes defined for Open edX User Notification data object.
Arguments:
user_ids (List(int)): identifier of the user to which the notification belongs.
user_ids (List(int)): identifier of the users to which the notification belongs.
notification_type (str): type of the notification.
context (dict): additional structured information about the context in
which this topic is used, such as the section, subsection etc.
content_url (str): url of the content.
app_name (str): name of the app.
course_key (str): identifier of the Course object.
context (dict): additional structured information about the context of the notification.
"""

user_ids = attr.ib(type=List[int])
Expand Down Expand Up @@ -425,3 +425,47 @@ class DiscussionThreadData:
user_course_roles = attr.ib(type=List[str], factory=list)
user_forums_roles = attr.ib(type=List[str], factory=list)
options = attr.ib(type=dict, factory=dict)


@attr.s(frozen=True)
class CourseNotificationData:
"""
Attributes defined for Open edX Course Notification data object.
Arguments:
course_key (str): identifier of the Course object.
app_name (str): name of the app requesting the course notification.
notification_type (str): type of the notification.
content_url (str): url of the content the notification will redirect to.
content_context (dict): additional information related to the content of the notification.
Notification content templates are defined in edx-platform here:
https://github.com/openedx/edx-platform/blob/master/openedx/core/djangoapps/notifications/base_notification.py#L10
Example of content_context for a discussion notification (new_comment_on_response):
{
...,
"content_context": {
"post_title": "Post Title",
"replier_name": "test_user",
}
audience_filters (dict): additional information related to the audience of the notification.
We can have different filters on course level, such as roles, enrollments, cohorts etc.
Example of audience_filters for a discussion notification (new_discussion_post):
{
...,
"audience_filters": {
"enrollment": ["verified", "audit"],
"role": ["discussion admin", "discussion moderator"],
}
"""

course_key = attr.ib(type=CourseKey)
app_name = attr.ib(type=str)
notification_type = attr.ib(type=str)
content_url = attr.ib(type=str)
content_context = attr.ib(type=dict, factory=dict)
audience_filters = attr.ib(type=dict, factory=dict)
17 changes: 16 additions & 1 deletion openedx_events/learning/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CohortData,
CourseDiscussionConfigurationData,
CourseEnrollmentData,
CourseNotificationData,
DiscussionThreadData,
ExamAttemptData,
ManageStudentsPermissionData,
Expand Down Expand Up @@ -188,7 +189,7 @@
)

# .. event_type: org.openedx.learning.user.notification.requested.v1
# .. event_name: USER_NOTIFICATION
# .. event_name: USER_NOTIFICATION_REQUESTED
# .. event_description: Can be fired from apps to send user notifications.
# .. event_data: UserNotificationSendListData
# Warning: This event is currently incompatible with the event bus, list/dict cannot be serialized yet
Expand Down Expand Up @@ -312,3 +313,17 @@
"thread": DiscussionThreadData,
}
)


# .. 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
# .. event_data: CourseNotificationData
# Warning: This event is currently incompatible with the event bus, list/dict cannot be serialized yet
#
COURSE_NOTIFICATION_REQUESTED = OpenEdxPublicSignal(
event_type="org.openedx.learning.course.notification.requested.v1",
data={
"course_notification_data": CourseNotificationData,
}
)
1 change: 1 addition & 0 deletions openedx_events/tooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"org.openedx.learning.thread.created.v1",
"org.openedx.learning.response.created.v1",
"org.openedx.learning.comment.created.v1",
"org.openedx.learning.course.notification.requested.v1",
]


Expand Down

0 comments on commit 1a5f9ca

Please sign in to comment.