diff --git a/src/registrar/management/commands/disclose_security_emails.py b/src/registrar/management/commands/disclose_security_emails.py index ff26e4882..a7ea0d2dd 100644 --- a/src/registrar/management/commands/disclose_security_emails.py +++ b/src/registrar/management/commands/disclose_security_emails.py @@ -12,6 +12,7 @@ from registrar.models import Domain logger = logging.getLogger(__name__) + class Command(BaseCommand): help = "Disclose all nondefault domain security emails." @@ -19,13 +20,13 @@ class Command(BaseCommand): """Sets global variables for code tidyness""" super().__init__() # domains and transition domains that must be disclosed to true - self.domains_to_disclose: List[str] = [] + self.contacts_saved: list[str] = [] # domains with errors, which are not successfully updated to disclose - self.domains_with_errors: List[str] = [] + self.domains_with_errors: list[str] = [] # domains that are successfully disclosed - self.disclosed_domain_contacts: List[str] = [] + self.disclosed_domain_contacts: list[str] = [] # domains that skip disclose due to having contact registrar@dotgov.gov - self.skipped_domain_contacts: List[str] = [] + self.skipped_domain_contacts: list[str] = [] def handle(self, **options): """ @@ -33,18 +34,20 @@ class Command(BaseCommand): to disclose their public contact. """ logger.info("Updating security emails to public") - + # Initializes domains that need to be disclosed - statuses=["ready", "dns needed"] - domains = Domain.objects.filter( - state__in=statuses - ) - + + statuses = ["ready", "dns needed"] + domains = Domain.objects.filter(state__in=statuses) + + logger.info("Found %d domains with status Ready or DNS Needed.", len(domains)) + # Call security_contact on all domains to trigger saving contact information for domain in domains: contact = domain.security_contact + self.contacts_saved.append(copy.deepcopy(contact)) - logger.info("Found %d domains with status Ready or DNS Needed.", len(domains)) + logger.info("Found %d security contacts.", len(self.contacts_saved)) # Update EPP contact for domains with a security contact for domain in domains: @@ -54,8 +57,11 @@ class Command(BaseCommand): domain._update_epp_contact(contact=domain.security_contact) self.disclosed_domain_contacts.append(copy.deepcopy(domain.security_contact)) else: - logger.info("Skipping disclose for %s security contact %s.", - domain.domain_info, domain.security_contact.email) + logger.info( + "Skipping disclose for %s security contact %s.", + domain.domain_info, + domain.security_contact.email, + ) self.skipped_domain_contacts.append(copy.deepcopy(domain.security_contact)) except Exception as err: # error condition if domain not in database @@ -64,7 +70,7 @@ class Command(BaseCommand): # Inform user how many contacts were disclosed and skipped logger.info("Updated %d contacts to disclosed.", len(self.disclosed_domain_contacts)) - logger.info("Skipped disclosing %d contacts with security email registrar@dotgov.gov.", - len(self.skipped_domain_contacts)) - - + logger.info( + "Skipped disclosing %d contacts with security email registrar@dotgov.gov.", + len(self.skipped_domain_contacts), + ) diff --git a/src/registrar/tests/test_models_domain.py b/src/registrar/tests/test_models_domain.py index 9c0a73a0a..81b63e3f6 100644 --- a/src/registrar/tests/test_models_domain.py +++ b/src/registrar/tests/test_models_domain.py @@ -549,7 +549,7 @@ class TestRegistrantContacts(MockEppLib): self.domain_contact._invalidate_cache() PublicContact.objects.all().delete() Domain.objects.all().delete() - + def run_disclose_security_emails(self): """ This method executes the disclose_security_emails command. @@ -977,7 +977,7 @@ class TestRegistrantContacts(MockEppLib): self.mockedSendFunction.assert_any_call(expectedCreateCommand, cleaned=True) # Confirm that we are getting the desired email self.assertEqual(domain.security_contact.email, expectedSecContact.email) - + def test_disclose_security_emails(self): """ Tests that command disclose_security_emails runs successfully with