mostly linted

Signed-off-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
CocoByte 2023-10-19 22:45:16 -06:00
parent 7998508881
commit bc14129f95
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
2 changed files with 29 additions and 29 deletions

View file

@ -83,22 +83,21 @@ class User(AbstractUser):
) )
def create_domain_and_invite(self, transition_domain: TransitionDomain): def create_domain_and_invite(self, transition_domain: TransitionDomain):
print("creating DOMAIN") transition_domain_name = transition_domain.domain_name
new_domain = Domain( transition_domain_status = transition_domain.status
name=transition_domain.domain_name, state=transition_domain.status transition_domain_email = transition_domain.username
)
new_domain = Domain(name=transition_domain_name, state=transition_domain_status)
new_domain.save() new_domain.save()
# check that a domain invitation doesn't already # check that a domain invitation doesn't already
# exist for this e-mail / Domain pair # exist for this e-mail / Domain pair
domain_email_already_in_domain_invites = DomainInvitation.objects.filter( domain_email_already_in_domain_invites = DomainInvitation.objects.filter(
email=transition_domain.username.lower(), domain=new_domain email=transition_domain_email.lower(), domain=new_domain
).exists() ).exists()
if not domain_email_already_in_domain_invites: if not domain_email_already_in_domain_invites:
print("creating INVITATION")
# Create new domain invitation # Create new domain invitation
new_domain_invitation = DomainInvitation( new_domain_invitation = DomainInvitation(
email=transition_domain.username.lower(), domain=new_domain email=transition_domain_email.lower(), domain=new_domain
) )
new_domain_invitation.save() new_domain_invitation.save()
@ -107,18 +106,16 @@ class User(AbstractUser):
if they are logging in with the same e-mail as a if they are logging in with the same e-mail as a
transition domain and update our database accordingly.""" transition domain and update our database accordingly."""
for transition_domain in TransitionDomain.objects.filter( for transition_domain in TransitionDomain.objects.filter(username=self.email):
username=self.email
):
# Looks like the user logged in with the same e-mail as # Looks like the user logged in with the same e-mail as
# one or more corresponding transition domains. # one or more corresponding transition domains.
# Create corresponding DomainInformation objects. # Create corresponding DomainInformation objects.
# NOTE: adding an ADMIN user role for this user # NOTE: adding an ADMIN user role for this user
# for each domain should already be done # for each domain should already be done
# in the invitation.retrieve() method. # in the invitation.retrieve() method.
# However, if the migration scripts for transition # However, if the migration scripts for transition
# domain objects were not executed correctly, # domain objects were not executed correctly,
# there could be transition domains without # there could be transition domains without
# any corresponding Domain & DomainInvitation objects, # any corresponding Domain & DomainInvitation objects,
# which means the invitation.retrieve() method might # which means the invitation.retrieve() method might
@ -128,12 +125,16 @@ class User(AbstractUser):
# with our data and migrations need to be run again. # with our data and migrations need to be run again.
# Get the domain that corresponds with this transition domain # Get the domain that corresponds with this transition domain
domain_exists = Domain.objects.filter(name=transition_domain.domain_name).exists() domain_exists = Domain.objects.filter(
name=transition_domain.domain_name
).exists()
if not domain_exists: if not domain_exists:
logger.warn("""There are transition domains without logger.warn(
corresponding domain objects! """There are transition domains without
corresponding domain objects!
Please run migration scripts for transition domains Please run migration scripts for transition domains
(See data_migration.md)""") (See data_migration.md)"""
)
# No need to throw an exception...just create a domain # No need to throw an exception...just create a domain
# and domain invite, then proceed as normal # and domain invite, then proceed as normal
self.create_domain_and_invite(transition_domain) self.create_domain_and_invite(transition_domain)
@ -146,9 +147,7 @@ class User(AbstractUser):
domain=domain domain=domain
).exists() ).exists()
if not domain_info_exists: if not domain_info_exists:
new_domain_info = DomainInformation( new_domain_info = DomainInformation(creator=self, domain=domain)
creator=self,
domain=domain)
new_domain_info.save() new_domain_info.save()
def first_login(self): def first_login(self):
@ -162,7 +161,7 @@ class User(AbstractUser):
""" """
# PART 1: TRANSITION DOMAINS # PART 1: TRANSITION DOMAINS
# #
# NOTE: THIS MUST RUN FIRST # NOTE: THIS MUST RUN FIRST
# (If we have an issue where transition domains were # (If we have an issue where transition domains were
# not fully converted into Domain and DomainInvitation # not fully converted into Domain and DomainInvitation
@ -173,7 +172,6 @@ class User(AbstractUser):
# PART 2: DOMAIN INVITATIONS # PART 2: DOMAIN INVITATIONS
self.check_domain_invitations_on_login() self.check_domain_invitations_on_login()
class Meta: class Meta:
permissions = [ permissions = [

View file

@ -614,8 +614,9 @@ class TestInvitations(TestCase):
self.user.first_login() self.user.first_login()
self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain)) self.assertTrue(UserDomainRole.objects.get(user=self.user, domain=self.domain))
class TestUser(TestCase): class TestUser(TestCase):
"""For now, just test actions that """For now, just test actions that
occur on user login.""" occur on user login."""
def setUp(self): def setUp(self):
@ -626,8 +627,9 @@ class TestUser(TestCase):
# clean out the roles each time # clean out the roles each time
UserDomainRole.objects.all().delete() UserDomainRole.objects.all().delete()
TransitionDomain.objects.get_or_create(username="mayor@igorville.gov", TransitionDomain.objects.get_or_create(
domain_name=self.domain_name) username="mayor@igorville.gov", domain_name=self.domain_name
)
def tearDown(self): def tearDown(self):
super().tearDown() super().tearDown()
@ -644,10 +646,10 @@ class TestUser(TestCase):
self.user.first_login() self.user.first_login()
self.assertTrue(DomainInformation.objects.get(domain=self.domain)) self.assertTrue(DomainInformation.objects.get(domain=self.domain))
def test_check_transition_domains_without_domains_on_login(self): def test_check_transition_domains_without_domains_on_login(self):
"""A new user's first_login callback checks transition domains. """A new user's first_login callback checks transition domains.
This test makes sure that in the event a domain does not exist This test makes sure that in the event a domain does not exist
for a given transition domain, both a domain and domain invitation for a given transition domain, both a domain and domain invitation
are created.""" are created."""
self.user.first_login() self.user.first_login()
@ -655,4 +657,4 @@ class TestUser(TestCase):
domain = 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(DomainInvitation.objects.get(email=self.email, domain=domain))
self.assertTrue(DomainInformation.objects.get(domain=domain)) self.assertTrue(DomainInformation.objects.get(domain=domain))