Skip to content

Commit

Permalink
Merge pull request #1192 from openedx/ahtesham/1865
Browse files Browse the repository at this point in the history
fix: remove username and change the subject in emails
  • Loading branch information
ahtesham-quraish committed Mar 19, 2024
2 parents df957ae + 9d4eb5d commit 7d021f5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 26 deletions.
20 changes: 4 additions & 16 deletions edx_proctoring/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1662,7 +1662,6 @@ def update_attempt_status(attempt_id, to_status,
}
)
email = create_proctoring_attempt_status_email(
user_id,
exam_attempt_obj,
course_name,
exam['course_id']
Expand Down Expand Up @@ -1730,15 +1729,14 @@ def update_attempt_status(attempt_id, to_status,
return attempt['id']


def create_proctoring_attempt_status_email(user_id, exam_attempt_obj, course_name, course_id):
def create_proctoring_attempt_status_email(exam_attempt_obj, course_name, course_id):
"""
Creates an email about change in proctoring attempt status.
"""
# Don't send an email unless this is a non-practice proctored exam
if not exam_attempt_obj.taking_as_proctored or exam_attempt_obj.is_sample_attempt:
return None

user = USER_MODEL.objects.get(id=user_id)
email_subject = (
_('Proctoring Results For {course_name} {exam_name}').format(
course_name=course_name,
Expand All @@ -1748,16 +1746,13 @@ def create_proctoring_attempt_status_email(user_id, exam_attempt_obj, course_nam
status = exam_attempt_obj.status
if status == ProctoredExamStudentAttemptStatus.submitted:
template_name = 'proctoring_attempt_submitted_email.html'
email_subject = (
_('Proctoring Review In Progress For {course_name} {exam_name}').format(
course_name=course_name,
exam_name=exam_attempt_obj.proctored_exam.exam_name
)
)
email_subject = 'Proctoring attempt submitted'
elif status == ProctoredExamStudentAttemptStatus.verified:
template_name = 'proctoring_attempt_satisfactory_email.html'
email_subject = 'Proctoring attempt verified'
elif status == ProctoredExamStudentAttemptStatus.rejected:
template_name = 'proctoring_attempt_unsatisfactory_email.html'
email_subject = 'Proctoring attempt rejected'
else:
# Don't send an email for any other attempt status codes
return None
Expand All @@ -1767,11 +1762,6 @@ def create_proctoring_attempt_status_email(user_id, exam_attempt_obj, course_nam
course_home_url = get_course_home_url(exam_attempt_obj.proctored_exam.course_id)

exam_name = exam_attempt_obj.proctored_exam.exam_name
support_email_subject = _('Proctored exam {exam_name} in {course_name} for user {username}').format(
exam_name=exam_name,
course_name=course_name,
username=user.username,
)

scheme = 'https' if getattr(settings, 'HTTPS', 'on') == 'on' else 'http'
default_contact_url = f'{scheme}://{constants.SITE_NAME}/support/contact_us'
Expand All @@ -1788,13 +1778,11 @@ def create_proctoring_attempt_status_email(user_id, exam_attempt_obj, course_nam
contact_url_text = contact_url

body = email_template.render({
'username': user.username,
'course_url': course_home_url,
'course_name': course_name,
'exam_name': exam_name,
'status': status,
'platform': constants.PLATFORM_NAME,
'support_email_subject': support_email_subject,
'contact_url': contact_url,
'contact_url_text': contact_url_text,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
{% block introduction %}
{% blocktrans %}
Hello {{ username }},
Hello,
{% endblocktrans %}
{% endblock %}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
{% block introduction %}
{% blocktrans %}
Hello {{ username }},
Hello,
{% endblocktrans %}
{% endblock %}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p>
{% block introduction %}
{% blocktrans %}
Hello {{ username }},
Hello,
{% endblocktrans %}
{% endblock %}
</p>
Expand Down
12 changes: 5 additions & 7 deletions edx_proctoring/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ def tearDown(self):
@ddt.data(
[
ProctoredExamStudentAttemptStatus.submitted,
'Proctoring Review In Progress',
'Proctoring attempt submitted',
'was submitted successfully',
],
[
ProctoredExamStudentAttemptStatus.verified,
'Proctoring Results',
'Proctoring attempt verified',
'was reviewed and you met all proctoring requirements',
],
[
ProctoredExamStudentAttemptStatus.rejected,
'Proctoring Results',
'Proctoring attempt rejected',
'the course team has identified one or more violations',
]
)
Expand All @@ -84,11 +84,10 @@ def test_send_email(self, status, expected_subject, expected_message_string):
# Verify the subject
actual_subject = self._normalize_whitespace(mail.outbox[0].subject)
self.assertIn(expected_subject, actual_subject)
self.assertIn(self.exam_name, actual_subject)

# Verify the body
actual_body = self._normalize_whitespace(mail.outbox[0].body)
self.assertIn('Hello tester,', actual_body)
self.assertIn('Hello,', actual_body)
self.assertIn('Your proctored exam "Test Exam"', actual_body)
self.assertIn(credit_state['course_name'], actual_body)
self.assertIn(expected_message_string, actual_body)
Expand Down Expand Up @@ -223,8 +222,7 @@ def test_send_email_unicode(self):

# Verify the subject
actual_subject = self._normalize_whitespace(mail.outbox[0].subject)
self.assertIn('Proctoring Review In Progress', actual_subject)
self.assertIn(course_name, actual_subject)
self.assertIn('Proctoring attempt submitted', actual_subject)

# Verify the body
actual_body = self._normalize_whitespace(mail.outbox[0].body)
Expand Down

0 comments on commit 7d021f5

Please sign in to comment.