From a8957fd118a80f34a074a3ce263c90914ddf9885 Mon Sep 17 00:00:00 2001 From: Bianca Severino Date: Mon, 26 Apr 2021 12:06:15 -0400 Subject: [PATCH] refactor: remove verification approved emails from ACE --- .../verify_student/message_types.py | 20 +++++++-------- .../verify_student/tests/test_views.py | 25 +++++++++++++++++++ lms/djangoapps/verify_student/views.py | 18 +++++++++++-- .../emails/passed_verification_email.txt | 11 ++++---- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/lms/djangoapps/verify_student/message_types.py b/lms/djangoapps/verify_student/message_types.py index 6401e1a805..12f1e790c8 100644 --- a/lms/djangoapps/verify_student/message_types.py +++ b/lms/djangoapps/verify_student/message_types.py @@ -4,16 +4,6 @@ ACE message types for the verify_student module. from openedx.core.djangoapps.ace_common.message import BaseMessageType -class VerificationExpiry(BaseMessageType): # lint-amnesty, pylint: disable=missing-class-docstring - APP_LABEL = 'verify_student' - Name = 'verificationexpiry' - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - self.options['transactional'] = True - - class VerificationApproved(BaseMessageType): """ A message to the learner when their ID verification has been approved. @@ -26,6 +16,16 @@ class VerificationApproved(BaseMessageType): self.options['transactional'] = True +class VerificationExpiry(BaseMessageType): # lint-amnesty, pylint: disable=missing-class-docstring + APP_LABEL = 'verify_student' + Name = 'verificationexpiry' + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.options['transactional'] = True + + class VerificationSubmitted(BaseMessageType): """ A confirmation message to the learner when their ID verification has been submitted. diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 0ad7be60da..fc1ab4ce00 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -1664,6 +1664,31 @@ class TestPhotoVerificationResultsCallback(ModuleStoreTestCase, TestVerification } mock_segment_track.assert_called_with(attempt.user.id, "edx.bi.experiment.verification.attempt.result", data) + @patch.dict(settings.VERIFY_STUDENT, {'USE_DJANGO_MAIL': True}) + def test_approved_email_without_ace(self): + """ + Test basic email for verification approved. + """ + expiration_datetime = now() + timedelta( + days=settings.VERIFY_STUDENT["DAYS_GOOD_FOR"] + ) + + data = { + "EdX-ID": self.receipt_id, + "Result": "PASS", + "Reason": "", + "MessageType": "You have been verified." + } + json_data = json.dumps(data) + self.client.post( + reverse('verify_student_results_callback'), data=json_data, + content_type='application/json', + HTTP_AUTHORIZATION='test BBBBBBBBBBBBBBBBBBBB:testing', + HTTP_DATE='testdate' + ) + + self._assert_verification_approved_email(expiration_datetime.date()) + @patch( 'lms.djangoapps.verify_student.ssencrypt.has_valid_signature', mock.Mock(side_effect=mocked_has_valid_signature) diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 9a626c0ff0..5e4bd6d935 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -1149,8 +1149,22 @@ def results_callback(request): # lint-amnesty, pylint: disable=too-many-stateme attempt.approve() expiration_datetime = attempt.expiration_datetime.date() - email_context = {'user': user, 'expiration_datetime': expiration_datetime.strftime("%m/%d/%Y")} - send_verification_approved_email(context=email_context) + if settings.VERIFY_STUDENT.get('USE_DJANGO_MAIL'): + verification_status_email_vars['expiration_datetime'] = expiration_datetime.strftime("%m/%d/%Y") + verification_status_email_vars['full_name'] = user.profile.name + subject = _("Your {platform_name} ID verification was approved!").format( + platform_name=settings.PLATFORM_NAME + ) + context = { + 'subject': subject, + 'template': 'emails/passed_verification_email.txt', + 'email': user.email, + 'email_vars': verification_status_email_vars + } + send_verification_status_email.delay(context) + else: + email_context = {'user': user, 'expiration_datetime': expiration_datetime.strftime("%m/%d/%Y")} + send_verification_approved_email(context=email_context) elif result == "FAIL": log.debug("Denying verification for %s", receipt_id) diff --git a/lms/templates/emails/passed_verification_email.txt b/lms/templates/emails/passed_verification_email.txt index 6770dd28ee..e2ad087811 100644 --- a/lms/templates/emails/passed_verification_email.txt +++ b/lms/templates/emails/passed_verification_email.txt @@ -1,10 +1,11 @@ <%! from django.utils.translation import ugettext as _ %> -${_("Hi {full_name}").format(full_name=full_name)} +${_("Hello {full_name},").format(full_name=full_name)} -${_("Congratulations! Your ID verification process was successful.")} -${_("Your verification is effective for two years. It will expire on {expiration_datetime}").format(expiration_date=expiration_datetime)} +${_("Your {platform_name} ID verification photos have been approved.").format(platform_name=platform_name)} -${_("Thank you,")} -${_("The {platform_name} team").format(platform_name=platform_name)} +${_("Your approval status remains valid for two years, and it will expire {expiration_datetime}.").format(expiration_datetime=expiration_datetime)} + +${_("Enjoy your studies,")} +${_("The {platform_name} Team").format(platform_name=platform_name)}