From c07e83b77dbdd1b0d5abc20bb18690435e8da7dc Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Jan 2024 08:18:20 -0700 Subject: [PATCH 1/4] Update src/registrar/views/application.py Co-authored-by: Alysia Broddrick <109625347+abroddrick@users.noreply.github.com> --- src/registrar/views/application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index b58deecc4..3e45778d1 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -679,7 +679,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) From e5fbd65847f6afbb47a3d9df0f73ed754f48001d Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Jan 2024 08:20:52 -0700 Subject: [PATCH 2/4] Update src/registrar/tests/test_views.py Co-authored-by: Alysia Broddrick <109625347+abroddrick@users.noreply.github.com> --- src/registrar/tests/test_views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 28074dd76..b1b112cb8 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 From 7c4a0a6de551a27f7ef058cea2af54217c36c838 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Jan 2024 08:26:47 -0700 Subject: [PATCH 3/4] PR suggestions --- src/registrar/models/utility/domain_helper.py | 3 --- src/registrar/views/application.py | 21 ++++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) 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/views/application.py b/src/registrar/views/application.py index b58deecc4..56048a23e 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -658,13 +658,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 From 688257a71823a8aa37c59bcd5baf6c1b45e19d7d Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Tue, 23 Jan 2024 08:44:39 -0700 Subject: [PATCH 4/4] Linting --- src/registrar/views/application.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index 1147d93eb..6a9d3f817 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -667,17 +667,17 @@ class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView): """ 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, + 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. + 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. + 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 = []