This commit is contained in:
CocoByte 2023-10-02 23:43:22 -06:00
parent e8409a1c2c
commit 1633feb57b
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
4 changed files with 82 additions and 14 deletions

View file

@ -5,6 +5,7 @@ import logging
import argparse
from collections import defaultdict
from django_fsm import TransitionNotAllowed # type: ignore
from django.core.management import BaseCommand
@ -64,6 +65,8 @@ class Command(BaseCommand):
to_create = []
# domains we UPDATED
updated_domain_entries = []
# domains we SKIPPED
skipped_domain_entries = []
# if we are limiting our parse (for testing purposes, keep
# track of total rows parsed)
total_rows_parsed = 0
@ -81,20 +84,32 @@ Beginning Data Transfer
# Check for existing domain entry
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
existingEntry = Domain.objects.get(
name=transition_domain_name
)
if transition_domain_status is TransitionDomain.StatusChoices.HOLD:
existingEntry.place_client_hold()
else:
existingEntry._remove_client_hold()
updated_domain_entries.append(existingEntry)
current_state = existingEntry.state
# DEBUG:
if debug_on:
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:
# no matching entry, make one
newEntry = Domain(
@ -119,6 +134,15 @@ Domain table for domain:
)
import sys
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:
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
{termColors.ENDC}
"""
)
if len(skipped_domain_entries) > 0:
logger.info(
f"""{termColors.FAIL}
============= SKIPPED DOMAINS (ERRORS) ===============
{skipped_domain_entries}
{termColors.ENDC}
"""
)
# DEBUG:

View file

@ -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",
),
),
]

View file

@ -783,20 +783,27 @@ class Domain(TimeStampedModel, DomainHelper):
@transition(
field="state", source=[State.READY, State.ON_HOLD], target=State.ON_HOLD
)
def place_client_hold(self):
"""place a clienthold on a domain (no longer should resolve)"""
def place_client_hold(self, ignoreEPP=False):
"""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
# (check prohibited statuses)
logger.info("clientHold()-> inside clientHold")
self._place_client_hold()
# In order to allow transition domains to by-pass EPP calls,
# include this ignoreEPP flag
if not ignoreEPP:
self._place_client_hold()
# TODO -on the client hold ticket any additional error handling here
@transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY)
def revert_client_hold(self):
"""undo a clienthold placed on a domain"""
def revert_client_hold(self, ignoreEPP=False):
"""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")
self._remove_client_hold()
if not ignoreEPP:
self._remove_client_hold()
# TODO -on the client hold ticket any additional error handling here
@transition(

View file

@ -5,7 +5,7 @@ from .utility.time_stamped_model import TimeStampedModel
class StatusChoices(models.TextChoices):
READY = "ready", "Ready"
HOLD = "hold", "Hold"
ON_HOLD = "on hold", "On Hold"
class TransitionDomain(TimeStampedModel):
@ -13,6 +13,10 @@ class TransitionDomain(TimeStampedModel):
state of a domain upon transition between registry
providers"""
# This is necessary to expose the enum to external
# classes that import TransitionDomain
StatusChoices = StatusChoices
username = models.TextField(
null=False,
blank=False,