Merge branch 'main' into dk/1410-display-expiration

This commit is contained in:
David Kennedy 2023-12-14 04:22:30 -05:00
commit 59fdb0aa12
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
11 changed files with 258 additions and 45 deletions

View file

@ -752,6 +752,7 @@ class TransitionDomainAdmin(ListHeaderAdmin):
"domain_name", "domain_name",
"status", "status",
"email_sent", "email_sent",
"processed",
] ]
search_fields = ["username", "domain_name"] search_fields = ["username", "domain_name"]

View file

@ -536,8 +536,8 @@ class Command(BaseCommand):
domain_name=new_entry_domain_name, domain_name=new_entry_domain_name,
) )
if not existing_entry.processed:
if existing_entry.status != new_entry_status: if existing_entry.status != new_entry_status:
# DEBUG:
TerminalHelper.print_conditional( TerminalHelper.print_conditional(
debug_on, debug_on,
f"{TerminalColors.OKCYAN}" f"{TerminalColors.OKCYAN}"
@ -549,6 +549,14 @@ class Command(BaseCommand):
existing_entry.status = new_entry_status existing_entry.status = new_entry_status
existing_entry.email_sent = new_entry_emailSent existing_entry.email_sent = new_entry_emailSent
existing_entry.save() existing_entry.save()
else:
TerminalHelper.print_conditional(
debug_on,
f"{TerminalColors.YELLOW}"
f"Skipping update on processed domain: {existing_entry}"
f"{TerminalColors.ENDC}",
)
except TransitionDomain.MultipleObjectsReturned: except TransitionDomain.MultipleObjectsReturned:
logger.info( logger.info(
f"{TerminalColors.FAIL}" f"{TerminalColors.FAIL}"
@ -558,6 +566,7 @@ class Command(BaseCommand):
f"----------TERMINATING----------" f"----------TERMINATING----------"
) )
sys.exit() sys.exit()
else: else:
# no matching entry, make one # no matching entry, make one
new_entry = TransitionDomain( new_entry = TransitionDomain(
@ -565,6 +574,7 @@ class Command(BaseCommand):
domain_name=new_entry_domain_name, domain_name=new_entry_domain_name,
status=new_entry_status, status=new_entry_status,
email_sent=new_entry_emailSent, email_sent=new_entry_emailSent,
processed=False,
) )
to_create.append(new_entry) to_create.append(new_entry)
total_new_entries += 1 total_new_entries += 1

View file

@ -559,7 +559,8 @@ class Command(BaseCommand):
debug_max_entries_to_parse, debug_max_entries_to_parse,
total_rows_parsed, total_rows_parsed,
): ):
for transition_domain in TransitionDomain.objects.all(): changed_transition_domains = TransitionDomain.objects.filter(processed=False)
for transition_domain in changed_transition_domains:
( (
target_domain_information, target_domain_information,
associated_domain, associated_domain,
@ -644,7 +645,8 @@ class Command(BaseCommand):
debug_max_entries_to_parse, debug_max_entries_to_parse,
total_rows_parsed, total_rows_parsed,
): ):
for transition_domain in TransitionDomain.objects.all(): changed_transition_domains = TransitionDomain.objects.filter(processed=False)
for transition_domain in changed_transition_domains:
# Create some local variables to make data tracing easier # Create some local variables to make data tracing easier
transition_domain_name = transition_domain.domain_name transition_domain_name = transition_domain.domain_name
transition_domain_status = transition_domain.status transition_domain_status = transition_domain.status
@ -796,6 +798,7 @@ class Command(BaseCommand):
# First, save all Domain objects to the database # First, save all Domain objects to the database
Domain.objects.bulk_create(domains_to_create) Domain.objects.bulk_create(domains_to_create)
# DomainInvitation.objects.bulk_create(domain_invitations_to_create) # DomainInvitation.objects.bulk_create(domain_invitations_to_create)
# TODO: this is to resolve an error where bulk_create # TODO: this is to resolve an error where bulk_create
@ -847,6 +850,15 @@ class Command(BaseCommand):
) )
DomainInformation.objects.bulk_create(domain_information_to_create) DomainInformation.objects.bulk_create(domain_information_to_create)
# Loop through the list of everything created, and mark it as processed
for domain in domains_to_create:
name = domain.name
TransitionDomain.objects.filter(domain_name=name).update(processed=True)
# Loop through the list of everything updated, and mark it as processed
for name in updated_domain_entries:
TransitionDomain.objects.filter(domain_name=name).update(processed=True)
self.print_summary_of_findings( self.print_summary_of_findings(
domains_to_create, domains_to_create,
updated_domain_entries, updated_domain_entries,

View file

@ -155,13 +155,13 @@ class LoadExtraTransitionDomain:
def update_transition_domain_models(self): def update_transition_domain_models(self):
"""Updates TransitionDomain objects based off the file content """Updates TransitionDomain objects based off the file content
given in self.parsed_data_container""" given in self.parsed_data_container"""
all_transition_domains = TransitionDomain.objects.all() valid_transition_domains = TransitionDomain.objects.filter(processed=False)
if not all_transition_domains.exists(): if not valid_transition_domains.exists():
raise ValueError("No TransitionDomain objects exist.") raise ValueError("No updatable TransitionDomain objects exist.")
updated_transition_domains = [] updated_transition_domains = []
failed_transition_domains = [] failed_transition_domains = []
for transition_domain in all_transition_domains: for transition_domain in valid_transition_domains:
domain_name = transition_domain.domain_name domain_name = transition_domain.domain_name
updated_transition_domain = transition_domain updated_transition_domain = transition_domain
try: try:
@ -228,7 +228,7 @@ class LoadExtraTransitionDomain:
# DATA INTEGRITY CHECK # DATA INTEGRITY CHECK
# Make sure every Transition Domain got updated # Make sure every Transition Domain got updated
total_transition_domains = len(updated_transition_domains) total_transition_domains = len(updated_transition_domains)
total_updates_made = TransitionDomain.objects.all().count() total_updates_made = TransitionDomain.objects.filter(processed=False).count()
if total_transition_domains != total_updates_made: if total_transition_domains != total_updates_made:
# noqa here for line length # noqa here for line length
logger.error( logger.error(
@ -787,7 +787,7 @@ class OrganizationDataLoader:
self.tds_to_update: List[TransitionDomain] = [] self.tds_to_update: List[TransitionDomain] = []
def update_organization_data_for_all(self): def update_organization_data_for_all(self):
"""Updates org address data for all TransitionDomains""" """Updates org address data for valid TransitionDomains"""
all_transition_domains = TransitionDomain.objects.all() all_transition_domains = TransitionDomain.objects.all()
if len(all_transition_domains) == 0: if len(all_transition_domains) == 0:
raise LoadOrganizationError(code=LoadOrganizationErrorCodes.EMPTY_TRANSITION_DOMAIN_TABLE) raise LoadOrganizationError(code=LoadOrganizationErrorCodes.EMPTY_TRANSITION_DOMAIN_TABLE)

View file

@ -0,0 +1,21 @@
# Generated by Django 4.2.7 on 2023-12-12 21:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("registrar", "0054_alter_domainapplication_federal_agency_and_more"),
]
operations = [
migrations.AddField(
model_name="transitiondomain",
name="processed",
field=models.BooleanField(
default=True,
help_text="Indicates whether this TransitionDomain was already processed",
verbose_name="Processed",
),
),
]

View file

@ -6,7 +6,7 @@ import django_fsm
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
("registrar", "0054_alter_domainapplication_federal_agency_and_more"), ("registrar", "0055_transitiondomain_processed"),
] ]
operations = [ operations = [

View file

@ -43,6 +43,12 @@ class TransitionDomain(TimeStampedModel):
verbose_name="email sent", verbose_name="email sent",
help_text="indicates whether email was sent", help_text="indicates whether email was sent",
) )
processed = models.BooleanField(
null=False,
default=True,
verbose_name="Processed",
help_text="Indicates whether this TransitionDomain was already processed",
)
organization_type = models.TextField( organization_type = models.TextField(
max_length=255, max_length=255,
null=True, null=True,

View file

@ -12,9 +12,11 @@
<p>You can enter your name servers, as well as other DNS-related information, in the following sections:</p> <p>You can enter your name servers, as well as other DNS-related information, in the following sections:</p>
{% url 'domain-dns-nameservers' pk=domain.id as url %} {% url 'domain-dns-nameservers' pk=domain.id as url %}
<p><a href="{{ url }}">DNS name servers</a></p> <ul>
<li><a href="{{ url }}">Name servers</a></li>
{% url 'domain-dns-dnssec' pk=domain.id as url %} {% url 'domain-dns-dnssec' pk=domain.id as url %}
<p><a href="{{ url }}">DNSSEC</a></p> <li><a href="{{ url }}">DNSSEC</a></li>
</ul>
{% endblock %} {# domain_content #} {% endblock %} {# domain_content #}

View file

@ -1,50 +1,62 @@
{% if is_federal %} {% if is_federal %}
{% if federal_type == 'executive' %} {% if federal_type == 'executive' %}
<p>Domain requests from executive branch agencies must be authorized by <strong>Chief Information Officers</strong> or <strong>agency heads</strong>.</p> <h3>Executive branch federal agencies</h3>
<p>Domain requests from executive branch agencies are subject to guidance issued by the U.S. Office of Management and Budget. </p> <p>Domain requests from executive branch federal agencies must be authorized by the agency's CIO or the head of the agency.</p>
<p>See <a class="usa-link usa-link--external" rel="noopener noreferrer" target="_blank" href="https://www.whitehouse.gov/wp-content/uploads/2023/02/M-23-10-DOTGOV-Act-Guidance.pdf">OMB Memorandum M-23-10</a> for more information.</p>
{% elif federal_type == 'judicial' %} {% elif federal_type == 'judicial' %}
<p>Domain requests from the U.S. Supreme Court must be authorized by the <strong>director of information technology for the U.S. Supreme Court.</strong></p> <h3>Judicial branch federal agencies</h3>
<p>Domain requests from other judicial branch agencies must be authorized by the <strong>director</strong> or <strong>Chief Information Officer of the Administrative Office (AO)</strong> of the United States Courts. <p>Domain requests for judicial branch federal agencies, except the U.S. Supreme Court, must be authorized by the director or CIO of the Administrative Office (AO) of the United States Courts.</p>
</p> <p>Domain requests from the U.S. Supreme Court must be authorized by the director of information technology for the U.S. Supreme Court.</p>
{% elif federal_type == 'legislative' %} {% elif federal_type == 'legislative' %}
<h3> U.S. Senate </h3> <h3>Legislative branch federal agencies</h3>
<p>Domain requests from the U.S. Senate must come from the <strong>Senate Sergeant at Arms.</strong></p>
<h3> U.S. House of Representatives </h3> <h4>U.S. Senate</h4>
<p class="">Domain requests from the U.S. House of Representatives must come from the <strong>House Chief Administrative Officer.</strong> <p>Domain requests from the U.S. Senate must come from the Senate Sergeant at Arms.</p>
<h3> Other legislative branch agencies </h3> <h4>U.S. House of Representatives</h4>
<p class="margin-top-1">Domain requests from legislative branch agencies must come from the <strong>agencys head</strong> or <strong>Chief Information Officer.</strong></p> <p>Domain requests from the U.S. House of Representatives must come from the House Chief Administrative Officer.</p>
<p class="margin-top-1">Domain requests from legislative commissions must come from the <strong>head of the commission</strong>, or the <strong>head or Chief Information Officer of the parent agency,</strong> if there is one.
</p> <h4>Other legislative branch agencies</h4>
<p>Domain requests from legislative branch agencies must come from the agencys head or CIO.</p>
<p>Domain requests from legislative commissions must come from the head of the commission, or the head or CIO of the parent agency, if there is one.</p>
{% endif %} {% endif %}
{% elif organization_type == 'city' %} {% elif organization_type == 'city' %}
<p>Domain requests from cities must be authorized by <strong>the mayor</strong> or the equivalent <strong>highest-elected official.</strong></p> <h3>Cities</h3>
<p>Domain requests from cities must be authorized by someone in a role of significant, executive responsibility within the city (mayor, council president, city manager, township/village supervisor, select board chairperson, chief, senior technology officer, or equivalent).</p>
{% elif organization_type == 'county' %} {% elif organization_type == 'county' %}
<p>Domain requests from counties must be authorized by the <strong>chair of the county commission </strong>or <strong>the equivalent highest-elected official.</strong></p> <h3>Counties</h3>
<p>Domain requests from counties must be authorized by the commission chair or someone in a role of significant, executive responsibility within the county (county judge, county mayor, parish/borough president, senior technology officer, or equivalent). Other county-level offices (county clerk, sheriff, county auditor, comptroller) may qualify, as well, in some instances.</p>
{% elif organization_type == 'interstate' %} {% elif organization_type == 'interstate' %}
<p>Domain requests from interstate organizations must be authorized by the <strong>highest-ranking executive</strong> (president, director, chair, or equivalent) or <strong>one of the states governors or Chief Information Officers.</strong></p> <h3>Interstate organizations</h3>
<p>Domain requests from interstate organizations must be authorized by someone in a role of significant, executive responsibility within the organization (president, director, chair, senior technology officer, or equivalent) or one of the states governors or CIOs.</p>
{% elif organization_type == 'school_district' %} {% elif organization_type == 'school_district' %}
<p>Domain requests from school district governments must be authorized by the <strong>highest-ranking executive (the chair of a school districts board or a superintendent)</strong>.</p> <h3>School districts</h3>
<p>Domain requests from school district governments must be authorized by someone in a role of significant, executive responsibility within the district (board chair, superintendent, senior technology officer, or equivalent).</p>
{% elif organization_type == 'special_district' %} {% elif organization_type == 'special_district' %}
<p>Domain requests from special districts must be authorized by the <strong>highest-ranking executive (president, director, chair, or equivalent)</strong> or <strong>state Chief Information Officers for state-based organizations</strong>.</p> <h3>Special districts</h3>
<p>Domain requests from special districts must be authorized by someone in a role of significant, executive responsibility within the district (CEO, chair, executive director, senior technology officer, or equivalent).
</p>
{% elif organization_type == 'state_or_territory' %} {% elif organization_type == 'state_or_territory' %}
<h3>States and territories: executive branch</h3> <h3>U.S. states and territories</h3>
<p>Domain requests from states and territories must be authorized by the <strong>governor</strong> or the <strong>state Chief Information Officer.</strong></p>
<h3>States and territories: judicial and legislative branches</h3> <h4>States and territories: executive branch</h4>
<p>Domain requests from state legislatures and courts must be authorized by an agencys <strong>Chief Information Officer</strong> or <strong>highest-ranking executive</strong>.</p> <p>Domain requests from states and territories must be authorized by the governor or someone in a role of significant, executive responsibility within the agency (department secretary, senior technology officer, or equivalent).</p>
<h4>States and territories: judicial and legislative branches</h4>
<p>Domain requests from state legislatures and courts must be authorized by an agencys CIO or someone in a role of significant, executive responsibility within the agency.</p>
{% elif organization_type == 'tribal' %} {% elif organization_type == 'tribal' %}
<p><strong>Domain requests from federally-recognized tribal governments must be authorized by the leader of the tribe</strong>, as recognized by the <a class="usa-link usa-link--external" rel="noopener noreferrer" target="_blank" href="https://www.bia.gov/service/tribal-leaders-directory">Bureau of Indian Affairs</a>.</p> <h3>Tribal governments</h3>
<p><strong>Domain requests from state-recognized tribal governments must be authorized by the leader of the tribe</strong>, as determined by the states tribal recognition initiative.</p> <p>Domain requests from federally-recognized tribal governments must be authorized by the tribal leader the <a class="usa-link usa-link--external" rel="noopener noreferrer" target="_blank" href="https://www.bia.gov/service/tribal-leaders-directory">Bureau of Indian Affairs</a> recognizes.</p>
<p>Domain requests from state-recognized tribal governments must be authorized by the tribal leader the individual state recognizes.</p>
{% endif %} {% endif %}

View file

@ -21,6 +21,155 @@ from registrar.models.contact import Contact
from .common import less_console_noise from .common import less_console_noise
class TestProcessedMigrations(TestCase):
"""This test case class is designed to verify the idempotency of migrations
related to domain transitions in the application."""
def setUp(self):
"""Defines the file name of migration_json and the folder its contained in"""
self.test_data_file_location = "registrar/tests/data"
self.migration_json_filename = "test_migrationFilepaths.json"
self.user, _ = User.objects.get_or_create(username="igorvillian")
def tearDown(self):
"""Deletes all DB objects related to migrations"""
# Delete domain information
Domain.objects.all().delete()
DomainInformation.objects.all().delete()
DomainInvitation.objects.all().delete()
TransitionDomain.objects.all().delete()
# Delete users
User.objects.all().delete()
UserDomainRole.objects.all().delete()
def run_load_domains(self):
"""
This method executes the load_transition_domain command.
It uses 'unittest.mock.patch' to mock the TerminalHelper.query_yes_no_exit method,
which is a user prompt in the terminal. The mock function always returns True,
allowing the test to proceed without manual user input.
The 'call_command' function from Django's management framework is then used to
execute the load_transition_domain command with the specified arguments.
"""
# noqa here because splitting this up makes it confusing.
# ES501
with patch(
"registrar.management.commands.utility.terminal_helper.TerminalHelper.query_yes_no_exit", # noqa
return_value=True,
):
call_command(
"load_transition_domain",
self.migration_json_filename,
directory=self.test_data_file_location,
)
def run_transfer_domains(self):
"""
This method executes the transfer_transition_domains_to_domains command.
The 'call_command' function from Django's management framework is then used to
execute the load_transition_domain command with the specified arguments.
"""
call_command("transfer_transition_domains_to_domains")
def test_domain_idempotent(self):
"""
This test ensures that the domain transfer process
is idempotent on Domain and DomainInformation.
"""
unchanged_domain, _ = Domain.objects.get_or_create(
name="testdomain.gov",
state=Domain.State.READY,
expiration_date=datetime.date(2000, 1, 1),
)
unchanged_domain_information, _ = DomainInformation.objects.get_or_create(
domain=unchanged_domain, organization_name="test org name", creator=self.user
)
self.run_load_domains()
# Test that a given TransitionDomain isn't set to "processed"
transition_domain_object = TransitionDomain.objects.get(domain_name="fakewebsite3.gov")
self.assertFalse(transition_domain_object.processed)
self.run_transfer_domains()
# Test that old data isn't corrupted
actual_unchanged = Domain.objects.filter(name="testdomain.gov").get()
actual_unchanged_information = DomainInformation.objects.filter(domain=actual_unchanged).get()
self.assertEqual(unchanged_domain, actual_unchanged)
self.assertEqual(unchanged_domain_information, actual_unchanged_information)
# Test that a given TransitionDomain is set to "processed" after we transfer domains
transition_domain_object = TransitionDomain.objects.get(domain_name="fakewebsite3.gov")
self.assertTrue(transition_domain_object.processed)
# Manually change Domain/DomainInformation objects
changed_domain = Domain.objects.filter(name="fakewebsite3.gov").get()
changed_domain.expiration_date = datetime.date(1999, 1, 1)
changed_domain.save()
changed_domain_information = DomainInformation.objects.filter(domain=changed_domain).get()
changed_domain_information.organization_name = "changed"
changed_domain_information.save()
# Rerun transfer domains
self.run_transfer_domains()
# Test that old data isn't corrupted after running this twice
actual_unchanged = Domain.objects.filter(name="testdomain.gov").get()
actual_unchanged_information = DomainInformation.objects.filter(domain=actual_unchanged).get()
self.assertEqual(unchanged_domain, actual_unchanged)
self.assertEqual(unchanged_domain_information, actual_unchanged_information)
# Ensure that domain hasn't changed
actual_domain = Domain.objects.filter(name="fakewebsite3.gov").get()
self.assertEqual(changed_domain, actual_domain)
# Ensure that DomainInformation hasn't changed
actual_domain_information = DomainInformation.objects.filter(domain=changed_domain).get()
self.assertEqual(changed_domain_information, actual_domain_information)
def test_transition_domain_is_processed(self):
"""
This test checks if a domain is correctly marked as processed in the transition.
"""
old_transition_domain, _ = TransitionDomain.objects.get_or_create(domain_name="testdomain.gov")
# Asser that old records default to 'True'
self.assertTrue(old_transition_domain.processed)
unchanged_domain, _ = Domain.objects.get_or_create(
name="testdomain.gov",
state=Domain.State.READY,
expiration_date=datetime.date(2000, 1, 1),
)
unchanged_domain_information, _ = DomainInformation.objects.get_or_create(
domain=unchanged_domain, organization_name="test org name", creator=self.user
)
self.run_load_domains()
# Test that a given TransitionDomain isn't set to "processed"
transition_domain_object = TransitionDomain.objects.get(domain_name="fakewebsite3.gov")
self.assertFalse(transition_domain_object.processed)
self.run_transfer_domains()
# Test that old data isn't corrupted
actual_unchanged = Domain.objects.filter(name="testdomain.gov").get()
actual_unchanged_information = DomainInformation.objects.filter(domain=actual_unchanged).get()
self.assertEqual(unchanged_domain, actual_unchanged)
self.assertTrue(old_transition_domain.processed)
self.assertEqual(unchanged_domain_information, actual_unchanged_information)
# Test that a given TransitionDomain is set to "processed" after we transfer domains
transition_domain_object = TransitionDomain.objects.get(domain_name="fakewebsite3.gov")
self.assertTrue(transition_domain_object.processed)
class TestOrganizationMigration(TestCase): class TestOrganizationMigration(TestCase):
def setUp(self): def setUp(self):
"""Defines the file name of migration_json and the folder its contained in""" """Defines the file name of migration_json and the folder its contained in"""

View file

@ -804,7 +804,7 @@ class DomainApplicationTests(TestWithUser, WebTest):
# ---- AO CONTACT PAGE ---- # ---- AO CONTACT PAGE ----
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)
ao_page = org_contact_result.follow() ao_page = org_contact_result.follow()
self.assertContains(ao_page, "Domain requests from executive branch agencies") self.assertContains(ao_page, "Executive branch federal agencies")
# Go back to organization type page and change type # Go back to organization type page and change type
self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id) self.app.set_cookie(settings.SESSION_COOKIE_NAME, session_id)