mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-17 15:04:11 +02:00
-s
This commit is contained in:
parent
e8409a1c2c
commit
1633feb57b
4 changed files with 82 additions and 14 deletions
|
@ -5,6 +5,7 @@ import logging
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from django_fsm import TransitionNotAllowed # type: ignore
|
||||||
|
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
|
@ -64,6 +65,8 @@ class Command(BaseCommand):
|
||||||
to_create = []
|
to_create = []
|
||||||
# domains we UPDATED
|
# domains we UPDATED
|
||||||
updated_domain_entries = []
|
updated_domain_entries = []
|
||||||
|
# domains we SKIPPED
|
||||||
|
skipped_domain_entries = []
|
||||||
# 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
|
||||||
|
@ -81,20 +84,32 @@ Beginning Data Transfer
|
||||||
|
|
||||||
# Check for existing domain entry
|
# Check for existing domain entry
|
||||||
try:
|
try:
|
||||||
|
# DEBUG:
|
||||||
|
if debug_on:
|
||||||
|
logger.info(f"""{termColors.WARNING}
|
||||||
|
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}{termColors.ENDC}""")
|
||||||
|
|
||||||
# for existing entry, update the status to the transition domain status
|
# for existing entry, update the status to the transition domain status
|
||||||
existingEntry = Domain.objects.get(
|
existingEntry = Domain.objects.get(
|
||||||
name=transition_domain_name
|
name=transition_domain_name
|
||||||
)
|
)
|
||||||
if transition_domain_status is TransitionDomain.StatusChoices.HOLD:
|
current_state = existingEntry.state
|
||||||
existingEntry.place_client_hold()
|
|
||||||
else:
|
|
||||||
existingEntry._remove_client_hold()
|
|
||||||
updated_domain_entries.append(existingEntry)
|
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on:
|
if debug_on:
|
||||||
logger.info(f"""{termColors.WARNING}
|
logger.info(f"""{termColors.WARNING}
|
||||||
Updated Domain: {existingEntry}""")
|
> Found existing domain entry for: {transition_domain_name}, {current_state}{termColors.ENDC}""")
|
||||||
|
if transition_domain_status != current_state:
|
||||||
|
if transition_domain_status == TransitionDomain.StatusChoices.ON_HOLD:
|
||||||
|
existingEntry.place_client_hold(ignoreEPP=True)
|
||||||
|
else:
|
||||||
|
existingEntry.revert_client_hold(ignoreEPP=True)
|
||||||
|
existingEntry.save()
|
||||||
|
updated_domain_entries.append(existingEntry)
|
||||||
|
# DEBUG:
|
||||||
|
if debug_on:
|
||||||
|
logger.info(f"""{termColors.WARNING}
|
||||||
|
>> Updated {transition_domain_name} state from '{current_state}' to '{existingEntry.state}{termColors.ENDC}'""")
|
||||||
except Domain.DoesNotExist:
|
except Domain.DoesNotExist:
|
||||||
# no matching entry, make one
|
# no matching entry, make one
|
||||||
newEntry = Domain(
|
newEntry = Domain(
|
||||||
|
@ -119,6 +134,15 @@ Domain table for domain:
|
||||||
)
|
)
|
||||||
import sys
|
import sys
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
except TransitionNotAllowed as err:
|
||||||
|
skipped_domain_entries.append(transition_domain_name)
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.FAIL}
|
||||||
|
Unable to change state for {transition_domain_name}
|
||||||
|
TRANSITION NOT ALLOWED error message (internal):
|
||||||
|
{err}
|
||||||
|
----------SKIPPING----------"""
|
||||||
|
)
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
if debug_on or debug_max_entries_to_parse > 0:
|
if debug_on or debug_max_entries_to_parse > 0:
|
||||||
|
@ -147,6 +171,15 @@ Created {total_new_entries} transition domain entries,
|
||||||
updated {total_updated_domain_entries} transition domain entries
|
updated {total_updated_domain_entries} transition domain entries
|
||||||
{termColors.ENDC}
|
{termColors.ENDC}
|
||||||
"""
|
"""
|
||||||
|
)
|
||||||
|
if len(skipped_domain_entries) > 0:
|
||||||
|
logger.info(
|
||||||
|
f"""{termColors.FAIL}
|
||||||
|
|
||||||
|
============= SKIPPED DOMAINS (ERRORS) ===============
|
||||||
|
{skipped_domain_entries}
|
||||||
|
{termColors.ENDC}
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# DEBUG:
|
# DEBUG:
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 4.2.1 on 2023-10-03 05:43
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("registrar", "0032_alter_transitiondomain_status"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="transitiondomain",
|
||||||
|
name="status",
|
||||||
|
field=models.CharField(
|
||||||
|
blank=True,
|
||||||
|
choices=[("ready", "Ready"), ("on hold", "On Hold")],
|
||||||
|
default="ready",
|
||||||
|
help_text="domain status during the transfer",
|
||||||
|
max_length=255,
|
||||||
|
verbose_name="Status",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
|
@ -783,19 +783,26 @@ class Domain(TimeStampedModel, DomainHelper):
|
||||||
@transition(
|
@transition(
|
||||||
field="state", source=[State.READY, State.ON_HOLD], target=State.ON_HOLD
|
field="state", source=[State.READY, State.ON_HOLD], target=State.ON_HOLD
|
||||||
)
|
)
|
||||||
def place_client_hold(self):
|
def place_client_hold(self, ignoreEPP=False):
|
||||||
"""place a clienthold on a domain (no longer should resolve)"""
|
"""place a clienthold on a domain (no longer should resolve)
|
||||||
|
ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)"""
|
||||||
# TODO - ensure all requirements for client hold are made here
|
# TODO - ensure all requirements for client hold are made here
|
||||||
# (check prohibited statuses)
|
# (check prohibited statuses)
|
||||||
logger.info("clientHold()-> inside clientHold")
|
logger.info("clientHold()-> inside clientHold")
|
||||||
|
|
||||||
|
# In order to allow transition domains to by-pass EPP calls,
|
||||||
|
# include this ignoreEPP flag
|
||||||
|
if not ignoreEPP:
|
||||||
self._place_client_hold()
|
self._place_client_hold()
|
||||||
# TODO -on the client hold ticket any additional error handling here
|
# TODO -on the client hold ticket any additional error handling here
|
||||||
|
|
||||||
@transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY)
|
@transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY)
|
||||||
def revert_client_hold(self):
|
def revert_client_hold(self, ignoreEPP=False):
|
||||||
"""undo a clienthold placed on a domain"""
|
"""undo a clienthold placed on a domain
|
||||||
|
ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)"""
|
||||||
|
|
||||||
logger.info("clientHold()-> inside clientHold")
|
logger.info("clientHold()-> inside clientHold")
|
||||||
|
if not ignoreEPP:
|
||||||
self._remove_client_hold()
|
self._remove_client_hold()
|
||||||
# TODO -on the client hold ticket any additional error handling here
|
# TODO -on the client hold ticket any additional error handling here
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from .utility.time_stamped_model import TimeStampedModel
|
||||||
|
|
||||||
class StatusChoices(models.TextChoices):
|
class StatusChoices(models.TextChoices):
|
||||||
READY = "ready", "Ready"
|
READY = "ready", "Ready"
|
||||||
HOLD = "hold", "Hold"
|
ON_HOLD = "on hold", "On Hold"
|
||||||
|
|
||||||
|
|
||||||
class TransitionDomain(TimeStampedModel):
|
class TransitionDomain(TimeStampedModel):
|
||||||
|
@ -13,6 +13,10 @@ class TransitionDomain(TimeStampedModel):
|
||||||
state of a domain upon transition between registry
|
state of a domain upon transition between registry
|
||||||
providers"""
|
providers"""
|
||||||
|
|
||||||
|
# This is necessary to expose the enum to external
|
||||||
|
# classes that import TransitionDomain
|
||||||
|
StatusChoices = StatusChoices
|
||||||
|
|
||||||
username = models.TextField(
|
username = models.TextField(
|
||||||
null=False,
|
null=False,
|
||||||
blank=False,
|
blank=False,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue