Remove submitter from deleting orphaned contacts

This commit is contained in:
Erin Song 2024-08-27 16:46:30 -07:00
parent d0b3dd7c46
commit 2c43533441
No known key found for this signature in database
3 changed files with 134 additions and 16 deletions

View file

@ -827,18 +827,16 @@ class DomainRequestDeleteView(DomainRequestPermissionDeleteView):
# Get each contact object on the DomainRequest object
so = domain_request.senior_official
creator = domain_request.creator
other_contacts = list(domain_request.other_contacts.all())
other_contact_ids = domain_request.other_contacts.all().values_list("id", flat=True)
# Check if the desired item still exists in the DB
if check_db:
so = self._get_contacts_by_id([so.id]).first() if so is not None else None
creator = self._get_contacts_by_id([creator.id]).first() if creator is not None else None
other_contacts = self._get_contacts_by_id(other_contact_ids)
# Pair each contact with its db related name for use in checking if it has joins
checked_contacts = [(so, "senior_official"), (creator, "submitted_domain_requests")]
checked_contacts = [(so, "senior_official")]
checked_contacts.extend((contact, "contact_domain_requests") for contact in other_contacts)
for contact, related_name in checked_contacts: