Skip to content

Commit

Permalink
Merge pull request #100 from edx/alangsto/update_proctoring_task
Browse files Browse the repository at this point in the history
fix: allow updates to proctoring verified name if it already exists
  • Loading branch information
alangsto authored Sep 9, 2022
2 parents 949c609 + cbaceac commit a2cd17a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[2.3.5] - 2022-09-09
~~~~~~~~~~~~~~~~~~~~
* Fix bug that prevents a verified name from being updated if the user already has an approved verified name associated with a proctored exam attempt

[2.3.4] - 2022-05-17
~~~~~~~~~~~~~~~~~~~~
* Fix bug that prevents new verified names from being created if the user is trying to verify the same name
Expand Down
2 changes: 1 addition & 1 deletion edx_name_affirmation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Django app housing name affirmation logic.
"""

__version__ = '2.3.4'
__version__ = '2.3.5'

default_app_config = 'edx_name_affirmation.apps.EdxNameAffirmationConfig' # pylint: disable=invalid-name
28 changes: 15 additions & 13 deletions edx_name_affirmation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,33 @@ def proctoring_update_verified_name_task(
Celery task for updating a verified name based on a proctoring attempt
"""

# check if approved VerifiedName already exists for the user
verified_name = VerifiedName.objects.filter(
approved_verified_name = VerifiedName.objects.filter(
user__id=user_id,
status=VerifiedNameStatus.APPROVED
).order_by('-created').first()
if verified_name:
approved_verified_name = verified_name.verified_name
is_full_name_approved = approved_verified_name == full_name

verified_name_for_exam = VerifiedName.objects.filter(
user__id=user_id,
proctored_exam_attempt_id=attempt_id
).order_by('-created').first()

# check if approved VerifiedName already exists for the user, and skip
# update if no VerifiedName has already been created for this specific exam
if approved_verified_name and not verified_name_for_exam:
is_full_name_approved = approved_verified_name.verified_name == full_name
if not is_full_name_approved:
log.warning(
'Full name for proctored_exam_attempt_id={attempt_id} is not equal '
'to the most recent verified name verified_name_id={name_id}.'.format(
attempt_id=attempt_id,
name_id=verified_name.id
name_id=approved_verified_name.id
)
)
return

verified_name = VerifiedName.objects.filter(
user__id=user_id,
proctored_exam_attempt_id=attempt_id
).order_by('-created').first()
if verified_name:
verified_name.status = name_affirmation_status
verified_name.save()
if verified_name_for_exam:
verified_name_for_exam.status = name_affirmation_status
verified_name_for_exam.save()
log.info(
'Updated VerifiedName for user={user_id} with proctored_exam_attempt_id={attempt_id} '
'to have status={status}'.format(
Expand Down
61 changes: 59 additions & 2 deletions edx_name_affirmation/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,9 @@ def test_proctoring_log_with_existing_approved_verified_name(self, should_names_
status=VerifiedNameStatus.APPROVED
)

additional_attempt_id = self.proctoring_attempt_id + 1
proctoring_attempt_handler(
self.proctoring_attempt_id,
additional_attempt_id,
self.user.id,
'created',
('John' if should_names_differ else self.verified_name),
Expand All @@ -449,7 +450,7 @@ def test_proctoring_log_with_existing_approved_verified_name(self, should_names_
'Full name for proctored_exam_attempt_id={attempt_id} is not equal to the most recent verified '
'name verified_name_id={verified_name_id}.'
).format(
attempt_id=self.proctoring_attempt_id,
attempt_id=additional_attempt_id,
verified_name_id=verified_name.id
)

Expand Down Expand Up @@ -499,3 +500,59 @@ def test_proctoring_delete_handler(self, mock_task):
)

mock_task.assert_called_with(None, mock_proctoring_object.id)

def test_proctoring_multiple_approved(self):
# create task for submitted exam
proctoring_attempt_handler(
self.proctoring_attempt_id,
self.user.id,
'submitted',
'John',
'John',
True,
True,
True
)

# create task for submitted on another exam
other_attempt_id = self.proctoring_attempt_id + 1
proctoring_attempt_handler(
other_attempt_id,
self.user.id,
'submitted',
'John',
'John',
True,
True,
True
)

self.assertEqual(len(VerifiedName.objects.filter()), 2)
self.assertEqual(len(VerifiedName.objects.filter(status=VerifiedNameStatus.SUBMITTED)), 2)

# create task for approved exam 1
proctoring_attempt_handler(
self.proctoring_attempt_id,
self.user.id,
'verified',
'John',
'John',
True,
True,
True
)

# create task for approved exam 2
proctoring_attempt_handler(
other_attempt_id,
self.user.id,
'verified',
'John',
'John',
True,
True,
True
)

self.assertEqual(len(VerifiedName.objects.filter()), 2)
self.assertEqual(len(VerifiedName.objects.filter(status=VerifiedNameStatus.APPROVED)), 2)

0 comments on commit a2cd17a

Please sign in to comment.