mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 19:20:47 +02:00
Merge branch 'main' into za/1484-domain-manager-delete
This commit is contained in:
commit
8c461942c8
3 changed files with 20 additions and 7 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue