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: [AXM-373] Add push notification event about course invitations #2557

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
20 changes: 20 additions & 0 deletions lms/djangoapps/instructor/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ def enroll_email(course_id, student_email, auto_enroll=False, email_students=Fal
"""
previous_state = EmailEnrollmentState(course_id, student_email)
enrollment_obj = None
if email_params:
email_params.update({
'app_label': 'instructor',
'push_notification_extra_context': {
'notification_type': 'enroll',
'course_id': str(course_id),
},
})
if previous_state.user and previous_state.user.is_active:
# if the student is currently unenrolled, don't enroll them in their
# previous mode
Expand Down Expand Up @@ -194,6 +202,13 @@ def unenroll_email(course_id, student_email, email_students=False, email_params=
representing state before and after the action.
"""
previous_state = EmailEnrollmentState(course_id, student_email)
if email_params:
email_params.update({
'app_label': 'instructor',
'push_notification_extra_context': {
'notification_type': 'unenroll',
},
})
if previous_state.enrollment:
CourseEnrollment.unenroll_by_email(student_email, course_id)
if email_students:
Expand Down Expand Up @@ -232,6 +247,11 @@ def send_beta_role_email(action, user, email_params):
email_params['email_address'] = user.email
email_params['user_id'] = user.id
email_params['full_name'] = user.profile.name
email_params['app_label'] = 'instructor'
email_params['push_notification_extra_context'] = {
'notification_type': email_params['message_type'],
'course_id': str(getattr(email_params.get('course'), 'id', '')),
}
else:
raise ValueError(f"Unexpected action received '{action}' - expected 'add' or 'remove'")
trying_to_add_inactive_user = not user.is_active and action == 'add'
Expand Down
5 changes: 5 additions & 0 deletions lms/templates/instructor/edx_ace/addbetatester/push/body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear {{ full_name }}{% endblocktrans %}
{% blocktrans %}You have been invited to be a beta tester for {{ course_name }} at {{ site_name }} by a member of the course staff.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been invited to a betca test for {{ course_name }}{% endblocktrans %}
{% endautoescape %}
5 changes: 5 additions & 0 deletions lms/templates/instructor/edx_ace/allowedenroll/push/body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear student,{% endblocktrans %}
{% blocktrans %}You have been invited to join {{ course_name }} at {{ site_name }} by a member of the course staff.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been invited to register for {{ course_name }}{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear Student,{% endblocktrans %}
{% blocktrans %}You have been unenrolled from the course {{ course_name }} by a member of the course staff. Please disregard the invitation previously sent.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been unenrolled from {{ course_name }}{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear {{ full_name }}{% endblocktrans %}
{% blocktrans %}You have been unenrolled from {{ course_name }} at {{ site_name }} by a member of the course staff. This course will no longer appear on your {{ site_name }} dashboard.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been unenrolled from {{ course_name }}{% endblocktrans %}
{% endautoescape %}
5 changes: 5 additions & 0 deletions lms/templates/instructor/edx_ace/enrollenrolled/push/body.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear {{ full_name }}{% endblocktrans %}
{% blocktrans %}You have been enrolled in {{ course_name }} at {{ site_name }} by a member of the course staff. This course will now appear on your {{ site_name }} dashboard.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been enrolled in {{ course_name }}{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Dear {{ full_name }}{% endblocktrans %}
{% blocktrans %}You have been removed as a beta tester for {{ course_name }} at {{ site_name }} by a member of the course staff. This course will remain on your dashboard, but you will no longer be part of the beta testing group.{% endblocktrans %}
{% endautoescape %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}You have been removed from a beta test for {{ course_name }}{% endblocktrans %}
{% endautoescape %}
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/notifications/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def check(self, message):
course_ids = message.context.get('course_ids', [])
app_label = message.context.get('app_label')

if not (app_label or message.context.get('send_push_notification', False)):
if not (app_label or message.context.get('push_notification_extra_context', {})):
return PolicyResult(deny={ChannelType.PUSH})

course_keys = [CourseKey.from_string(course_id) for course_id in course_ids]
Expand Down
Loading