From ba0b34e365091361b214ef7f9d87f26f4269bfa7 Mon Sep 17 00:00:00 2001 From: Ivan Niedielnitsev <81557788+NiedielnitsevIvan@users.noreply.github.com> Date: Tue, 14 May 2024 15:46:54 +0300 Subject: [PATCH] feat: [AXM-373] Add push notification event about course invitations (#2557) * feat: [AXM-373] add push notifications for user enroll * feat: [AXM-373] add push notifications for user unenroll * feat: [AXM-373] add push notifications for add course beta testers * feat: [AXM-373] add push notifications for remove course beta testers * style: [AXM-373] remove debugger * fix: [AXM-373] fix after demo --- lms/djangoapps/instructor/enrollment.py | 20 +++++++++++++++++++ .../edx_ace/addbetatester/push/body.txt | 5 +++++ .../edx_ace/addbetatester/push/subject.txt | 4 ++++ .../edx_ace/allowedenroll/push/body.txt | 5 +++++ .../edx_ace/allowedenroll/push/subject.txt | 4 ++++ .../edx_ace/allowedunenroll/push/body.txt | 5 +++++ .../edx_ace/allowedunenroll/push/subject.txt | 4 ++++ .../edx_ace/enrolledunenroll/push/body.txt | 5 +++++ .../edx_ace/enrolledunenroll/push/subject.txt | 4 ++++ .../edx_ace/enrollenrolled/push/body.txt | 5 +++++ .../edx_ace/enrollenrolled/push/subject.txt | 4 ++++ .../edx_ace/removebetatester/push/body.txt | 5 +++++ .../edx_ace/removebetatester/push/subject.txt | 4 ++++ .../core/djangoapps/notifications/policies.py | 2 +- 14 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 lms/templates/instructor/edx_ace/addbetatester/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/addbetatester/push/subject.txt create mode 100644 lms/templates/instructor/edx_ace/allowedenroll/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/allowedenroll/push/subject.txt create mode 100644 lms/templates/instructor/edx_ace/allowedunenroll/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/allowedunenroll/push/subject.txt create mode 100644 lms/templates/instructor/edx_ace/enrolledunenroll/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/enrolledunenroll/push/subject.txt create mode 100644 lms/templates/instructor/edx_ace/enrollenrolled/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/enrollenrolled/push/subject.txt create mode 100644 lms/templates/instructor/edx_ace/removebetatester/push/body.txt create mode 100644 lms/templates/instructor/edx_ace/removebetatester/push/subject.txt diff --git a/lms/djangoapps/instructor/enrollment.py b/lms/djangoapps/instructor/enrollment.py index 300543def6c2..4643cc307ad9 100644 --- a/lms/djangoapps/instructor/enrollment.py +++ b/lms/djangoapps/instructor/enrollment.py @@ -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 @@ -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: @@ -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' diff --git a/lms/templates/instructor/edx_ace/addbetatester/push/body.txt b/lms/templates/instructor/edx_ace/addbetatester/push/body.txt new file mode 100644 index 000000000000..9070f05db483 --- /dev/null +++ b/lms/templates/instructor/edx_ace/addbetatester/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/addbetatester/push/subject.txt b/lms/templates/instructor/edx_ace/addbetatester/push/subject.txt new file mode 100644 index 000000000000..ca1838195f55 --- /dev/null +++ b/lms/templates/instructor/edx_ace/addbetatester/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been invited to a betca test for {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/instructor/edx_ace/allowedenroll/push/body.txt b/lms/templates/instructor/edx_ace/allowedenroll/push/body.txt new file mode 100644 index 000000000000..cddc8d38e29b --- /dev/null +++ b/lms/templates/instructor/edx_ace/allowedenroll/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/allowedenroll/push/subject.txt b/lms/templates/instructor/edx_ace/allowedenroll/push/subject.txt new file mode 100644 index 000000000000..1cbe2a29ab05 --- /dev/null +++ b/lms/templates/instructor/edx_ace/allowedenroll/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been invited to register for {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/instructor/edx_ace/allowedunenroll/push/body.txt b/lms/templates/instructor/edx_ace/allowedunenroll/push/body.txt new file mode 100644 index 000000000000..5981633b96b8 --- /dev/null +++ b/lms/templates/instructor/edx_ace/allowedunenroll/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/allowedunenroll/push/subject.txt b/lms/templates/instructor/edx_ace/allowedunenroll/push/subject.txt new file mode 100644 index 000000000000..99aaa1a9c305 --- /dev/null +++ b/lms/templates/instructor/edx_ace/allowedunenroll/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been unenrolled from {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/instructor/edx_ace/enrolledunenroll/push/body.txt b/lms/templates/instructor/edx_ace/enrolledunenroll/push/body.txt new file mode 100644 index 000000000000..da9c3a3de00c --- /dev/null +++ b/lms/templates/instructor/edx_ace/enrolledunenroll/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/enrolledunenroll/push/subject.txt b/lms/templates/instructor/edx_ace/enrolledunenroll/push/subject.txt new file mode 100644 index 000000000000..99aaa1a9c305 --- /dev/null +++ b/lms/templates/instructor/edx_ace/enrolledunenroll/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been unenrolled from {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/instructor/edx_ace/enrollenrolled/push/body.txt b/lms/templates/instructor/edx_ace/enrollenrolled/push/body.txt new file mode 100644 index 000000000000..36bd69d7b72f --- /dev/null +++ b/lms/templates/instructor/edx_ace/enrollenrolled/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/enrollenrolled/push/subject.txt b/lms/templates/instructor/edx_ace/enrollenrolled/push/subject.txt new file mode 100644 index 000000000000..ebe884b30f08 --- /dev/null +++ b/lms/templates/instructor/edx_ace/enrollenrolled/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been enrolled in {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/instructor/edx_ace/removebetatester/push/body.txt b/lms/templates/instructor/edx_ace/removebetatester/push/body.txt new file mode 100644 index 000000000000..586a9385f988 --- /dev/null +++ b/lms/templates/instructor/edx_ace/removebetatester/push/body.txt @@ -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 %} diff --git a/lms/templates/instructor/edx_ace/removebetatester/push/subject.txt b/lms/templates/instructor/edx_ace/removebetatester/push/subject.txt new file mode 100644 index 000000000000..33dee3487f96 --- /dev/null +++ b/lms/templates/instructor/edx_ace/removebetatester/push/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}You have been removed from a beta test for {{ course_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/openedx/core/djangoapps/notifications/policies.py b/openedx/core/djangoapps/notifications/policies.py index 768d05e62efd..8467eda9324e 100644 --- a/openedx/core/djangoapps/notifications/policies.py +++ b/openedx/core/djangoapps/notifications/policies.py @@ -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]