mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 18:56:15 +02:00
linted
Signed-off-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
parent
6382b14c6e
commit
d617c2a315
1 changed files with 47 additions and 32 deletions
|
@ -113,7 +113,7 @@ class Command(BaseCommand):
|
||||||
updated_domain_entries,
|
updated_domain_entries,
|
||||||
domain_invitations_to_create,
|
domain_invitations_to_create,
|
||||||
skipped_domain_entries,
|
skipped_domain_entries,
|
||||||
debug_on
|
debug_on,
|
||||||
):
|
):
|
||||||
"""Prints to terminal a summary of findings from
|
"""Prints to terminal a summary of findings from
|
||||||
transferring transition domains to domains"""
|
transferring transition domains to domains"""
|
||||||
|
@ -147,7 +147,8 @@ class Command(BaseCommand):
|
||||||
for domain in domains_to_create:
|
for domain in domains_to_create:
|
||||||
skipped_domain_invitations.append(domain)
|
skipped_domain_invitations.append(domain)
|
||||||
for domain_invite in domain_invitations_to_create:
|
for domain_invite in domain_invitations_to_create:
|
||||||
if domain_invite.domain in skipped_domain_invitations: skipped_domain_invitations.remove(domain_invite.domain)
|
if domain_invite.domain in skipped_domain_invitations:
|
||||||
|
skipped_domain_invitations.remove(domain_invite.domain)
|
||||||
if len(skipped_domain_invitations) > 0:
|
if len(skipped_domain_invitations) > 0:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.FAIL}
|
f"""{termColors.FAIL}
|
||||||
|
@ -172,33 +173,46 @@ class Command(BaseCommand):
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
def try_add_domain_invitation(self,
|
def try_add_domain_invitation(
|
||||||
domain_email: str,
|
self, domain_email: str, associated_domain: Domain
|
||||||
associated_domain: Domain) -> DomainInvitation:
|
) -> DomainInvitation | None:
|
||||||
"""If no domain invitation exists for the given domain and
|
"""If no domain invitation exists for the given domain and
|
||||||
e-mail, create and return a new domain invitation object.
|
e-mail, create and return a new domain invitation object.
|
||||||
If one already exists, or if the email is invalid, return NONE"""
|
If one already exists, or if the email is invalid, return NONE"""
|
||||||
|
|
||||||
# this exception should never happen, but adding it just in case
|
# this should never happen, but adding it just in case
|
||||||
assert (associated_domain is None, "domain cannot be null for a Domain Invitation object!")
|
if associated_domain is None:
|
||||||
|
logger.warning(
|
||||||
|
f"""
|
||||||
|
{termColors.FAIL}
|
||||||
|
!!! ERROR: Domain cannot be null for a
|
||||||
|
Domain Invitation object!
|
||||||
|
|
||||||
|
RECOMMENDATION:
|
||||||
|
Somehow, an empty domain object is
|
||||||
|
being passed to the subroutine in charge
|
||||||
|
of making domain invitations. Walk through
|
||||||
|
the code to see what is amiss.
|
||||||
|
|
||||||
|
----------TERMINATING----------"""
|
||||||
|
)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# check that the given e-mail is valid
|
# check that the given e-mail is valid
|
||||||
if domain_email is not None and domain_email != "":
|
if domain_email is not None and domain_email != "":
|
||||||
# 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 = domain_email.lower(),
|
email=domain_email.lower(), domain=associated_domain
|
||||||
domain=associated_domain).exists()
|
).exists()
|
||||||
if not domain_email_already_in_domain_invites:
|
if not domain_email_already_in_domain_invites:
|
||||||
# Create new domain invitation
|
# Create new domain invitation
|
||||||
new_domain_invitation = DomainInvitation(
|
new_domain_invitation = DomainInvitation(
|
||||||
email=domain_email.lower(),
|
email=domain_email.lower(), domain=associated_domain
|
||||||
domain=associated_domain
|
|
||||||
)
|
)
|
||||||
return new_domain_invitation
|
return new_domain_invitation
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def handle(
|
def handle(
|
||||||
self,
|
self,
|
||||||
**options,
|
**options,
|
||||||
|
@ -249,9 +263,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
new_domain_invitation = None
|
new_domain_invitation = None
|
||||||
# Check for existing domain entry
|
# Check for existing domain entry
|
||||||
domain_exists = Domain.objects.filter(
|
domain_exists = Domain.objects.filter(name=transition_domain_name).exists()
|
||||||
name=transition_domain_name
|
|
||||||
).exists()
|
|
||||||
if domain_exists:
|
if domain_exists:
|
||||||
try:
|
try:
|
||||||
# get the existing domain
|
# get the existing domain
|
||||||
|
@ -273,9 +285,11 @@ class Command(BaseCommand):
|
||||||
# keep track of updated domains for data analysis purposes
|
# keep track of updated domains for data analysis purposes
|
||||||
updated_domain_entries.append(transition_domain.domain_name)
|
updated_domain_entries.append(transition_domain.domain_name)
|
||||||
|
|
||||||
# check if we need to add a domain invitation
|
# check if we need to add a domain invitation
|
||||||
# (eg. for a new user)
|
# (eg. for a new user)
|
||||||
new_domain_invitation = self.try_add_domain_invitation(transition_domain_email, domain_to_update)
|
new_domain_invitation = self.try_add_domain_invitation(
|
||||||
|
transition_domain_email, domain_to_update
|
||||||
|
)
|
||||||
|
|
||||||
except Domain.MultipleObjectsReturned:
|
except Domain.MultipleObjectsReturned:
|
||||||
# This exception was thrown once before during testing.
|
# This exception was thrown once before during testing.
|
||||||
|
@ -290,7 +304,7 @@ class Command(BaseCommand):
|
||||||
!!! ERROR: duplicate entries already exist in the
|
!!! ERROR: duplicate entries already exist in the
|
||||||
Domain table for the following domain:
|
Domain table for the following domain:
|
||||||
{transition_domain_name}
|
{transition_domain_name}
|
||||||
|
|
||||||
RECOMMENDATION:
|
RECOMMENDATION:
|
||||||
This means the Domain table is corrupt. Please
|
This means the Domain table is corrupt. Please
|
||||||
check the Domain table data as there should be a key
|
check the Domain table data as there should be a key
|
||||||
|
@ -304,7 +318,7 @@ class Command(BaseCommand):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"""{termColors.FAIL}
|
f"""{termColors.FAIL}
|
||||||
Unable to change state for {transition_domain_name}
|
Unable to change state for {transition_domain_name}
|
||||||
|
|
||||||
RECOMMENDATION:
|
RECOMMENDATION:
|
||||||
This indicates there might have been changes to the
|
This indicates there might have been changes to the
|
||||||
Domain model which were not accounted for in this
|
Domain model which were not accounted for in this
|
||||||
|
@ -339,21 +353,24 @@ class Command(BaseCommand):
|
||||||
Checking for unique user e-mail for Domain Invitations...
|
Checking for unique user e-mail for Domain Invitations...
|
||||||
{termColors.ENDC}""",
|
{termColors.ENDC}""",
|
||||||
)
|
)
|
||||||
new_domain_invitation = self.try_add_domain_invitation(transition_domain_email, existing_domain_in_to_create)
|
new_domain_invitation = self.try_add_domain_invitation(
|
||||||
|
transition_domain_email, existing_domain_in_to_create
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# no matching entry, make one
|
# no matching entry, make one
|
||||||
new_domain = Domain(
|
new_domain = Domain(
|
||||||
name=transition_domain_name,
|
name=transition_domain_name, state=transition_domain_status
|
||||||
state=transition_domain_status
|
|
||||||
)
|
)
|
||||||
domains_to_create.append(new_domain)
|
domains_to_create.append(new_domain)
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
self.print_debug(
|
self.print_debug(
|
||||||
debug_on,
|
debug_on,
|
||||||
f"{termColors.OKCYAN} Adding domain: {new_domain} {termColors.ENDC}"
|
f"{termColors.OKCYAN} Adding domain: {new_domain} {termColors.ENDC}", # noqa
|
||||||
)
|
)
|
||||||
new_domain_invitation = self.try_add_domain_invitation(transition_domain_email, new_domain)
|
new_domain_invitation = self.try_add_domain_invitation(
|
||||||
|
transition_domain_email, new_domain
|
||||||
|
)
|
||||||
|
|
||||||
if new_domain_invitation is None:
|
if new_domain_invitation is None:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{termColors.YELLOW} ! No new e-mail detected !" # noqa
|
f"{termColors.YELLOW} ! No new e-mail detected !" # noqa
|
||||||
|
@ -363,13 +380,11 @@ class Command(BaseCommand):
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
self.print_debug(
|
self.print_debug(
|
||||||
debug_on,
|
debug_on,
|
||||||
f"{termColors.OKCYAN} Adding domain invitation: {new_domain_invitation} {termColors.ENDC}",
|
f"{termColors.OKCYAN} Adding domain invitation: {new_domain_invitation} {termColors.ENDC}", # noqa
|
||||||
)
|
)
|
||||||
domain_invitations_to_create.append(new_domain_invitation)
|
domain_invitations_to_create.append(new_domain_invitation)
|
||||||
|
|
||||||
|
# Check parse limit and exit loop if parse limit has been reached
|
||||||
|
|
||||||
# Check parse limit
|
|
||||||
if (
|
if (
|
||||||
debug_max_entries_to_parse > 0
|
debug_max_entries_to_parse > 0
|
||||||
and total_rows_parsed >= debug_max_entries_to_parse
|
and total_rows_parsed >= debug_max_entries_to_parse
|
||||||
|
@ -390,5 +405,5 @@ class Command(BaseCommand):
|
||||||
updated_domain_entries,
|
updated_domain_entries,
|
||||||
domain_invitations_to_create,
|
domain_invitations_to_create,
|
||||||
skipped_domain_entries,
|
skipped_domain_entries,
|
||||||
debug_on
|
debug_on,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue