From 8b27c44b89f30632018f627fa6d6df882f5b3868 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 19 Apr 2024 15:47:03 -0600 Subject: [PATCH] Cleanup --- src/registrar/models/user.py | 40 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 423f93595..b67421d3f 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -113,10 +113,13 @@ class User(AbstractUser): def has_contact_info(self): return bool(self.contact.title or self.contact.email or self.contact.phone) - @classmethod - def existing_user(cls, uuid): - existing_user = None + def needs_identity_verification(cls, email, uuid): + """A method used by our oidc classes to test whether a user needs email/uuid verification + or the full identity PII verification""" + + # An existing user who is a domain manager of a domain (that is, + # they have an entry in UserDomainRole for their User) try: existing_user = cls.objects.get(username=uuid) if existing_user and UserDomainRole.objects.filter(user=existing_user).exists(): @@ -126,24 +129,21 @@ class User(AbstractUser): pass except Exception as err: raise err - - return True - @classmethod - def needs_identity_verification(cls, email, uuid): - """A method used by our oidc classes to test whether a user needs email/uuid verification - or the full identity PII verification""" - - # An existing user who is a domain manager of a domain (that is, - # they have an entry in UserDomainRole for their User) - user_exists = cls.existing_user(uuid) - if not user_exists: - return False + # We can't set the verification type here because the user may not + # always exist at this point. We do it down the line. + verification_type = cls.get_verification_type_from_email(email) # The user needs identity verification if they don't meet # any special criteria, i.e. we are validating them "regularly" - verification_type = cls.get_verification_type_from_email(email) - return verification_type == cls.VerificationTypeChoices.REGULAR + needs_verification = verification_type == cls.VerificationTypeChoices.REGULAR + return needs_verification + + def set_user_verification_type(self): + # Would need to check audit log + retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED + verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) + self.verification_type = verification_type @classmethod def get_verification_type_from_email(cls, email, invitation_status=DomainInvitation.DomainInvitationStatus.INVITED): @@ -167,12 +167,6 @@ class User(AbstractUser): return verification_type - def set_user_verification_type(self): - # Would need to check audit log - retrieved = DomainInvitation.DomainInvitationStatus.RETRIEVED - verification_type = self.get_verification_type_from_email(self.email, invitation_status=retrieved) - self.verification_type = verification_type - def check_domain_invitations_on_login(self): """When a user first arrives on the site, we need to retrieve any domain invitations that match their email address."""