diff --git a/edx_name_affirmation/migrations/0009_add_verifiedname_platform_verification_id.py b/edx_name_affirmation/migrations/0009_add_verifiedname_platform_verification_id.py new file mode 100644 index 0000000..b8eeaae --- /dev/null +++ b/edx_name_affirmation/migrations/0009_add_verifiedname_platform_verification_id.py @@ -0,0 +1,27 @@ +# Generated by Django 4.2.16 on 2024-09-19 12:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('edx_name_affirmation', '0008_alter_historicalverifiedname_options'), + ] + + operations = [ + migrations.AlterModelOptions( + name='historicalverifiedname', + options={'get_latest_by': 'history_date', 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical verified name'}, + ), + migrations.AddField( + model_name='historicalverifiedname', + name='platform_verification_attempt_id', + field=models.PositiveIntegerField(blank=True, null=True), + ), + migrations.AddField( + model_name='verifiedname', + name='platform_verification_attempt_id', + field=models.PositiveIntegerField(blank=True, null=True), + ), + ] diff --git a/edx_name_affirmation/models.py b/edx_name_affirmation/models.py index 8006fd3..d6fe988 100644 --- a/edx_name_affirmation/models.py +++ b/edx_name_affirmation/models.py @@ -39,6 +39,9 @@ class VerifiedName(TimeStampedModel): verification_attempt_id = models.PositiveIntegerField(null=True, blank=True) proctored_exam_attempt_id = models.PositiveIntegerField(null=True, blank=True) + # Reference to a generic VerificationAttempt object in the platform + platform_verification_attempt_id = models.PositiveIntegerField(null=True, blank=True) + status = models.CharField( max_length=32, choices=[(st.value, st.value) for st in VerifiedNameStatus], @@ -74,6 +77,15 @@ def verification_attempt_status(self): except ObjectDoesNotExist: return None + def save(self, *args, **kwargs): + """ + Validate only one of `verification_attempt_id` or `platform_verification_attempt_id` + can be set. + """ + if self.verification_attempt_id and self.platform_verification_attempt_id: + raise ValueError('Only one of `verification_attempt_id` or `platform_verification_attempt_id` can be set.') + super().save(*args, **kwargs) + class VerifiedNameConfig(ConfigurationModel): """ diff --git a/edx_name_affirmation/tests/test_models.py b/edx_name_affirmation/tests/test_models.py index dc2aac5..8a316c8 100644 --- a/edx_name_affirmation/tests/test_models.py +++ b/edx_name_affirmation/tests/test_models.py @@ -67,6 +67,15 @@ def test_verification_status(self, sspv_mock): self.verified_name.verification_attempt_id = self.idv_attempt_id assert self.verified_name.verification_attempt_status is self.idv_attempt_status + def test_verification_id_exclusivity(self): + """ + Test that only one verification ID can be set at a time + """ + self.verified_name.verification_attempt_id = 1 + self.verified_name.platform_verification_attempt_id = 1 + with self.assertRaises(ValueError): + self.verified_name.save() + # Helper methods def _obj(self, dictionary):