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,9 +106,7 @@ 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.
@ -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(
"""There are transition domains without
corresponding domain objects! 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):
@ -174,7 +173,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 = [
("analyst_access_permission", "Analyst Access Permission"), ("analyst_access_permission", "Analyst Access Permission"),

View file

@ -614,6 +614,7 @@ 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."""
@ -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()