diff --git a/src/registrar/models/utility/domain_helper.py b/src/registrar/models/utility/domain_helper.py index 3267f0c93..a808ef803 100644 --- a/src/registrar/models/utility/domain_helper.py +++ b/src/registrar/models/utility/domain_helper.py @@ -57,9 +57,6 @@ class DomainHelper: # If blank ok is true, just return the domain return domain - if domain.startswith("www."): - domain = domain[4:] - if domain.endswith(".gov"): domain = domain[:-4] diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index fda393439..5a32615a4 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -236,6 +236,7 @@ class LoggedInTests(TestWithUser): # Trigger the delete logic response = self.client.post(reverse("application-delete", kwargs={"pk": application.pk}), follow=True) + # igorville is now deleted self.assertNotContains(response, "igorville.gov") # Check if the orphaned contact was deleted diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index ac1d6f1e9..4e7180cd7 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -666,13 +666,28 @@ class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView): # This determines if any of these three fields share a contact, which is used for # the edge case where the same user may be an AO, and a submitter, for example. if len(duplicates) > 0: - duplicates_to_delete, _ = self._get_orphaned_contacts(application) + duplicates_to_delete, _ = self._get_orphaned_contacts(application, check_db=True) Contact.objects.filter(id__in=duplicates_to_delete, user=None).delete() return response - def _get_orphaned_contacts(self, application: DomainApplication, check_db=True): - """Collects all orphaned contacts""" + def _get_orphaned_contacts(self, application: DomainApplication, check_db=False): + """ + Collects all orphaned contacts associated with a given DomainApplication object. + + An orphaned contact is defined as a contact that is associated with the application, + but not with any other application. This includes the authorizing official, the submitter, + and any other contacts linked to the application. + + Parameters: + application (DomainApplication): The DomainApplication object for which to find orphaned contacts. + check_db (bool, optional): A flag indicating whether to check the database for the existence of the contacts. + Defaults to False. + + Returns: + tuple: A tuple containing two lists. The first list contains the IDs of the orphaned contacts. + The second list contains any duplicate contacts found. ([Contacts], [Contacts]) + """ contacts_to_delete = [] # Get each contact object on the DomainApplication object @@ -687,7 +702,7 @@ class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView): submitter = self._get_contacts_by_id([submitter.id]).first() if submitter is not None else None other_contacts = self._get_contacts_by_id(other_contact_ids) - # Pair each contact with its related name + # Pair each contact with its db related name for use in checking if it has joins checked_contacts = [(ao, "authorizing_official"), (submitter, "submitted_applications")] checked_contacts.extend((contact, "contact_applications") for contact in other_contacts)