mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 21:19:42 +02:00
Domain Invitation portion updated to catch anomalies
Signed-off-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
parent
bede4c8607
commit
7f7a6f1fdb
1 changed files with 70 additions and 39 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
from django_fsm import TransitionNotAllowed # type: ignore
|
from django_fsm import TransitionNotAllowed # type: ignore
|
||||||
|
|
||||||
|
@ -29,6 +30,23 @@ class termColors:
|
||||||
UNDERLINE = "\033[4m"
|
UNDERLINE = "\033[4m"
|
||||||
BackgroundLightYellow = "\033[103m"
|
BackgroundLightYellow = "\033[103m"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = """Load data from transition domain tables
|
||||||
|
into main domain tables. Also create domain invitation
|
||||||
|
entries for every domain we ADD (but not for domains
|
||||||
|
we UPDATE)"""
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument("--debug", action=argparse.BooleanOptionalAction)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--limitParse",
|
||||||
|
default=0,
|
||||||
|
help="Sets max number of entries to load, set to 0 to load all entries",
|
||||||
|
)
|
||||||
|
|
||||||
def print_debug_mode_statements(
|
def print_debug_mode_statements(
|
||||||
self, debug_on: bool, debug_max_entries_to_parse: int
|
self, debug_on: bool, debug_max_entries_to_parse: int
|
||||||
):
|
):
|
||||||
|
@ -54,21 +72,6 @@ class termColors:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
help = """Load data from transition domain tables
|
|
||||||
into main domain tables. Also create domain invitation
|
|
||||||
entries for every domain we ADD (but not for domains
|
|
||||||
we UPDATE)"""
|
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
parser.add_argument("--debug", action=argparse.BooleanOptionalAction)
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--limitParse",
|
|
||||||
default=0,
|
|
||||||
help="Sets max number of entries to load, set to 0 to load all entries",
|
|
||||||
)
|
|
||||||
|
|
||||||
def handle( # noqa: C901
|
def handle( # noqa: C901
|
||||||
self,
|
self,
|
||||||
**options,
|
**options,
|
||||||
|
@ -92,6 +95,8 @@ class Command(BaseCommand):
|
||||||
updated_domain_entries = []
|
updated_domain_entries = []
|
||||||
# domains we SKIPPED
|
# domains we SKIPPED
|
||||||
skipped_domain_entries = []
|
skipped_domain_entries = []
|
||||||
|
# domainInvitations we SKIPPED
|
||||||
|
skipped_domain_invitations = []
|
||||||
# if we are limiting our parse (for testing purposes, keep
|
# if we are limiting our parse (for testing purposes, keep
|
||||||
# track of total rows parsed)
|
# track of total rows parsed)
|
||||||
total_rows_parsed = 0
|
total_rows_parsed = 0
|
||||||
|
@ -114,8 +119,8 @@ class Command(BaseCommand):
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"""{termColors.YELLOW}
|
f"""{termColors.OKCYAN}
|
||||||
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}
|
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}, {transition_domain_email}
|
||||||
{termColors.ENDC}""" # noqa
|
{termColors.ENDC}""" # noqa
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -132,10 +137,7 @@ class Command(BaseCommand):
|
||||||
{termColors.ENDC}""" # noqa
|
{termColors.ENDC}""" # noqa
|
||||||
)
|
)
|
||||||
if transition_domain_status != current_state:
|
if transition_domain_status != current_state:
|
||||||
if (
|
if transition_domain_status == TransitionDomain.StatusChoices.ON_HOLD:
|
||||||
transition_domain_status
|
|
||||||
== TransitionDomain.StatusChoices.ON_HOLD
|
|
||||||
):
|
|
||||||
existingEntry.place_client_hold(ignoreEPP=True)
|
existingEntry.place_client_hold(ignoreEPP=True)
|
||||||
else:
|
else:
|
||||||
existingEntry.revert_client_hold(ignoreEPP=True)
|
existingEntry.revert_client_hold(ignoreEPP=True)
|
||||||
|
@ -151,23 +153,45 @@ class Command(BaseCommand):
|
||||||
{termColors.ENDC}"""
|
{termColors.ENDC}"""
|
||||||
)
|
)
|
||||||
except Domain.DoesNotExist:
|
except Domain.DoesNotExist:
|
||||||
|
|
||||||
|
already_in_to_create = next(
|
||||||
|
(x for x in domains_to_create if x.name == transition_domain_name),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if already_in_to_create:
|
||||||
|
# DEBUG:
|
||||||
|
if debug_on:
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.YELLOW}
|
||||||
|
Duplicate Detected: {transition_domain_name}.
|
||||||
|
Cannot add duplicate entry for another username.
|
||||||
|
Violates Unique Key constraint.
|
||||||
|
{termColors.ENDC}"""
|
||||||
|
)
|
||||||
|
else:
|
||||||
# no matching entry, make one
|
# no matching entry, make one
|
||||||
newEntry = Domain(
|
new_entry = Domain(
|
||||||
name=transition_domain_name, state=transition_domain_status
|
name=transition_domain_name, state=transition_domain_status
|
||||||
)
|
)
|
||||||
domains_to_create.append(newEntry)
|
domains_to_create.append(new_entry)
|
||||||
|
|
||||||
domain_invitations_to_create.append(
|
if transition_domain_email:
|
||||||
DomainInvitation(
|
new_domain_invitation = DomainInvitation(
|
||||||
email=transition_domain_email.lower(),
|
email=transition_domain_email.lower(),
|
||||||
domain=transition_domain_name,
|
domain=new_entry
|
||||||
)
|
)
|
||||||
|
domain_invitations_to_create.append(new_domain_invitation)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
f"{termColors.FAIL} ! No e-mail found for domain: {new_entry}"
|
||||||
|
f"(SKIPPED ADDING DOMAIN INVITATION){termColors.ENDC}"
|
||||||
)
|
)
|
||||||
|
skipped_domain_invitations.append(transition_domain_name)
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{termColors.OKCYAN} Adding domain AND domain invitation: {newEntry} {termColors.ENDC}" # noqa
|
f"{termColors.OKCYAN} Adding domain AND domain invitation: {new_entry} {termColors.ENDC}" # noqa
|
||||||
)
|
)
|
||||||
except Domain.MultipleObjectsReturned:
|
except Domain.MultipleObjectsReturned:
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -178,8 +202,6 @@ class Command(BaseCommand):
|
||||||
{transition_domain_name}
|
{transition_domain_name}
|
||||||
----------TERMINATING----------"""
|
----------TERMINATING----------"""
|
||||||
)
|
)
|
||||||
import sys
|
|
||||||
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
except TransitionNotAllowed as err:
|
except TransitionNotAllowed as err:
|
||||||
skipped_domain_entries.append(transition_domain_name)
|
skipped_domain_entries.append(transition_domain_name)
|
||||||
|
@ -194,7 +216,7 @@ class Command(BaseCommand):
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on or debug_max_entries_to_parse > 0:
|
if debug_on or debug_max_entries_to_parse > 0:
|
||||||
if (
|
if (
|
||||||
total_rows_parsed > debug_max_entries_to_parse
|
total_rows_parsed >= debug_max_entries_to_parse
|
||||||
and debug_max_entries_to_parse != 0
|
and debug_max_entries_to_parse != 0
|
||||||
):
|
):
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -231,6 +253,15 @@ class Command(BaseCommand):
|
||||||
{termColors.ENDC}
|
{termColors.ENDC}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
if len(skipped_domain_invitations) > 0:
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.FAIL}
|
||||||
|
============= SKIPPED DOMAIN INVITATIONS (ERRORS) ===============
|
||||||
|
{skipped_domain_invitations}
|
||||||
|
{termColors.ENDC}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue