From 6c0509d4b5911db01673245312dccac1e7543792 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 Nov 2023 09:51:32 -0700 Subject: [PATCH 1/3] Update user.py --- src/registrar/models/user.py | 56 ------------------------------------ 1 file changed, 56 deletions(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index bde73d3cb..69afa3899 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -97,51 +97,6 @@ class User(AbstractUser): new_domain_invitation = DomainInvitation(email=transition_domain_email.lower(), domain=new_domain) new_domain_invitation.save() - def check_transition_domains_on_login(self): - """When a user first arrives on the site, we need to check - if they are logging in with the same e-mail as a - transition domain and update our database accordingly.""" - - for transition_domain in TransitionDomain.objects.filter(username=self.email): - # Looks like the user logged in with the same e-mail as - # one or more corresponding transition domains. - # Create corresponding DomainInformation objects. - - # NOTE: adding an ADMIN user role for this user - # for each domain should already be done - # in the invitation.retrieve() method. - # However, if the migration scripts for transition - # domain objects were not executed correctly, - # there could be transition domains without - # any corresponding Domain & DomainInvitation objects, - # which means the invitation.retrieve() method might - # not execute. - # Check that there is a corresponding domain object - # for this transition domain. If not, we have an error - # with our data and migrations need to be run again. - - # Get the domain that corresponds with this transition domain - domain_exists = Domain.objects.filter(name=transition_domain.domain_name).exists() - if not domain_exists: - logger.warn( - """There are transition domains without - corresponding domain objects! - Please run migration scripts for transition domains - (See data_migration.md)""" - ) - # No need to throw an exception...just create a domain - # and domain invite, then proceed as normal - self.create_domain_and_invite(transition_domain) - - domain = Domain.objects.get(name=transition_domain.domain_name) - - # Create a domain information object, if one doesn't - # already exist - domain_info_exists = DomainInformation.objects.filter(domain=domain).exists() - if not domain_info_exists: - new_domain_info = DomainInformation(creator=self, domain=domain) - new_domain_info.save() - def on_each_login(self): """Callback each time the user is authenticated. @@ -152,17 +107,6 @@ class User(AbstractUser): as a transition domain and update our domainInfo objects accordingly. """ - # PART 1: TRANSITION DOMAINS - # - # NOTE: THIS MUST RUN FIRST - # (If we have an issue where transition domains were - # not fully converted into Domain and DomainInvitation - # objects, this method will fill in the gaps. - # This will ensure the Domain Invitations method - # runs correctly (no missing invites)) - self.check_transition_domains_on_login() - - # PART 2: DOMAIN INVITATIONS self.check_domain_invitations_on_login() class Meta: From f2f78e371b2a09f4f44f91181eb0924356bbe884 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 Nov 2023 09:53:08 -0700 Subject: [PATCH 2/3] Update test_models.py --- src/registrar/tests/test_models.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 58cf05115..684e90382 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -627,14 +627,6 @@ class TestUser(TestCase): TransitionDomain.objects.all().delete() User.objects.all().delete() - def test_check_transition_domains_on_login(self): - """A user's on_each_login callback checks transition domains. - Makes DomainInformation object.""" - self.domain, _ = Domain.objects.get_or_create(name=self.domain_name) - - self.user.on_each_login() - self.assertTrue(DomainInformation.objects.get(domain=self.domain)) - def test_check_transition_domains_without_domains_on_login(self): """A user's on_each_login callback checks transition domains. This test makes sure that in the event a domain does not exist From f71cded6e2681788b1f1e45ccbeeae7fd35f4cad Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:01:03 -0700 Subject: [PATCH 3/3] Update test cases / linter --- src/registrar/models/user.py | 1 - src/registrar/tests/test_models.py | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index 69afa3899..2daa3c253 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -5,7 +5,6 @@ from django.db import models from .domain_invitation import DomainInvitation from .transition_domain import TransitionDomain -from .domain_information import DomainInformation from .domain import Domain from phonenumber_field.modelfields import PhoneNumberField # type: ignore diff --git a/src/registrar/tests/test_models.py b/src/registrar/tests/test_models.py index 684e90382..d397cb129 100644 --- a/src/registrar/tests/test_models.py +++ b/src/registrar/tests/test_models.py @@ -628,13 +628,9 @@ class TestUser(TestCase): User.objects.all().delete() def test_check_transition_domains_without_domains_on_login(self): - """A user's on_each_login callback checks transition domains. + """A user's on_each_login callback does not check transition domains. This test makes sure that in the event a domain does not exist for a given transition domain, both a domain and domain invitation are created.""" self.user.on_each_login() - self.assertTrue(Domain.objects.get(name=self.domain_name)) - - domain = Domain.objects.get(name=self.domain_name) - self.assertTrue(DomainInvitation.objects.get(email=self.email, domain=domain)) - self.assertTrue(DomainInformation.objects.get(domain=domain)) + self.assertFalse(Domain.objects.filter(name=self.domain_name).exists())