From 1ce8c9aabf4db5f51401d0675569bce9495cc5b6 Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Tue, 17 May 2022 15:41:59 -0400 Subject: [PATCH] fix: allow verified name to be created if user is trying to verify with the same name --- CHANGELOG.rst | 5 ++++ edx_name_affirmation/__init__.py | 2 +- edx_name_affirmation/tasks.py | 11 +++++++- edx_name_affirmation/tests/test_handlers.py | 29 +++++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index c73dc67..621b710 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,11 @@ Change Log Unreleased ~~~~~~~~~~ + +[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 + [2.3.3] - 2022-04-21 ~~~~~~~~~~~~~~~~~~~~ * Leverage edx-api-doc-tools to provide better swagger documentation for the RESTFul API endpoints diff --git a/edx_name_affirmation/__init__.py b/edx_name_affirmation/__init__.py index 0b8d61b..06ef5fe 100644 --- a/edx_name_affirmation/__init__.py +++ b/edx_name_affirmation/__init__.py @@ -2,6 +2,6 @@ Django app housing name affirmation logic. """ -__version__ = '2.3.3' +__version__ = '2.3.4' default_app_config = 'edx_name_affirmation.apps.EdxNameAffirmationConfig' # pylint: disable=invalid-name diff --git a/edx_name_affirmation/tasks.py b/edx_name_affirmation/tasks.py index 13e7f64..dfafd49 100644 --- a/edx_name_affirmation/tasks.py +++ b/edx_name_affirmation/tasks.py @@ -9,6 +9,7 @@ from edx_django_utils.monitoring import set_code_owner_attribute from django.contrib.auth import get_user_model +from django.db.models import Q from edx_name_affirmation.models import VerifiedName from edx_name_affirmation.statuses import VerifiedNameStatus @@ -37,7 +38,15 @@ def idv_update_verified_name_task(self, attempt_id, user_id, name_affirmation_st 'status': name_affirmation_status } ) - verified_names = VerifiedName.objects.filter(user__id=user_id, verified_name=photo_id_name).order_by('-created') + # get all verified names that are either not associated with an IDV attempt, or + # only associated with the IDV attempt for which we received an update. We do not + # want to grab all verified names for the same user and name combination, because + # some of those records may already be associated with a different IDV attempt. + verified_names = VerifiedName.objects.filter( + (Q(verification_attempt_id=attempt_id) | Q(verification_attempt_id__isnull=True)) + & Q(user__id=user_id) + & Q(verified_name=photo_id_name) + ).order_by('-created') if verified_names: # if there are VerifiedName objects, we want to update existing entries # for each attempt with no attempt id (either proctoring or idv), update attempt id diff --git a/edx_name_affirmation/tests/test_handlers.py b/edx_name_affirmation/tests/test_handlers.py index d02b375..7c764ba 100644 --- a/edx_name_affirmation/tests/test_handlers.py +++ b/edx_name_affirmation/tests/test_handlers.py @@ -134,6 +134,35 @@ def test_idv_update_multiple_verified_names(self, idv_status, expected_status): self.assertEqual(len(VerifiedName.objects.filter(verification_attempt_id=self.idv_attempt_id)), 3) self.assertEqual(len(VerifiedName.objects.filter(status=expected_status)), 3) + def test_idv_create_with_existing_verified_names(self): + """ + Test that if a user attempts IDV again with the same name as previous attempts, we still create a new record + """ + previous_id = 1234567 + + VerifiedName.objects.create( + user=self.user, + verified_name=self.verified_name, + profile_name=self.profile_name, + verification_attempt_id=previous_id, + status='denied' + ) + + # create an IDV attempt with the same user and names as above, but change the attempt ID to a unique value + idv_attempt_handler( + self.idv_attempt_id, + self.user.id, + 'submitted', + self.verified_name, + self.profile_name + ) + + verified_name = VerifiedName.objects.get(verification_attempt_id=self.idv_attempt_id) + self.assertEqual(verified_name.status, VerifiedNameStatus.SUBMITTED) + + previous_name = VerifiedName.objects.get(verification_attempt_id=previous_id) + self.assertEqual(previous_name.status, VerifiedNameStatus.DENIED) + def test_idv_does_not_update_verified_name_by_proctoring(self): """ If the idv handler is triggered, ensure that the idv attempt info does not update any verified name