-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send IDV approval email in approve_id_verifications management …
…command This commit modifies the approve_id_verifications management command to send an IDV approval email to learners. This ensures that learners are informed of approvals to their IDV attempts when performed using the management command. This more closely mirrors the way IDV approvals work when using an IDV vendor.
- Loading branch information
1 parent
f12cd32
commit f94a7f7
Showing
5 changed files
with
115 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" | ||
API module. | ||
""" | ||
from django.conf import settings | ||
from django.utils.translation import gettext as _ | ||
|
||
from lms.djangoapps.verify_student.emails import send_verification_approved_email | ||
from lms.djangoapps.verify_student.tasks import send_verification_status_email | ||
|
||
|
||
def send_approval_email(attempt): | ||
""" | ||
Send an approval email to the learner associated with the IDV attempt. | ||
""" | ||
verification_status_email_vars = { | ||
'platform_name': settings.PLATFORM_NAME, | ||
} | ||
|
||
expiration_datetime = attempt.expiration_datetime.date() | ||
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'] = attempt.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': attempt.user.email, | ||
'email_vars': verification_status_email_vars | ||
} | ||
send_verification_status_email.delay(context) | ||
else: | ||
email_context = {'user': attempt.user, 'expiration_datetime': expiration_datetime.strftime("%m/%d/%Y")} | ||
send_verification_approved_email(context=email_context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Tests of API module. | ||
""" | ||
from unittest.mock import patch | ||
|
||
import ddt | ||
from django.conf import settings | ||
from django.core import mail | ||
from django.test import TestCase | ||
|
||
from common.djangoapps.student.tests.factories import UserFactory | ||
from lms.djangoapps.verify_student.api import send_approval_email | ||
from lms.djangoapps.verify_student.models import SoftwareSecurePhotoVerification | ||
|
||
|
||
@ddt.ddt | ||
class TestSendApprovalEmail(TestCase): | ||
""" | ||
Test cases for the send_approval_email API method. | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.user = UserFactory.create() | ||
self.attempt = SoftwareSecurePhotoVerification( | ||
status="submitted", | ||
user=self.user | ||
) | ||
self.attempt.save() | ||
|
||
def _assert_verification_approved_email(self, expiration_date): | ||
"""Check that a verification approved email was sent.""" | ||
assert len(mail.outbox) == 1 | ||
email = mail.outbox[0] | ||
assert email.subject == 'Your édX ID verification was approved!' | ||
assert 'Your édX ID verification photos have been approved' in email.body | ||
assert expiration_date.strftime("%m/%d/%Y") in email.body | ||
|
||
@ddt.data(True, False) | ||
def test_send_approval(self, use_ace): | ||
with patch.dict(settings.VERIFY_STUDENT, {'USE_DJANGO_MAIL': use_ace}): | ||
send_approval_email(self.attempt) | ||
self._assert_verification_approved_email(self.attempt.expiration_datetime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters