From 728457f18b97a1c4778c70db01f98a44e3760bed Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Fri, 21 Jun 2024 13:51:25 -0700 Subject: [PATCH] Check for incident member before re-adding --- src/dispatch/case/flows.py | 42 ++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/dispatch/case/flows.py b/src/dispatch/case/flows.py index f2a73a5c02a7..73c826e08b4f 100644 --- a/src/dispatch/case/flows.py +++ b/src/dispatch/case/flows.py @@ -646,28 +646,34 @@ def common_escalate_flow( # we add the case participants to the incident for participant in case.participants: - log.info( - f"Adding participant {participant.individual.email} from Case {case.id} to Incident {incident.id}" + # check to see if already a participant in the incident + incident_participant = participant_service.get_by_incident_id_and_email( + db_session=db_session, incident_id=incident.id, email=participant.individual.email ) - # Get the roles for this participant - case_roles = participant.participant_roles - # Map the case role to an incident role - incident_role = ParticipantRoleType.map_case_role_to_incident_role(case_roles) + if not incident_participant: + log.info( + f"Adding participant {participant.individual.email} from Case {case.id} to Incident {incident.id}" + ) + # Get the roles for this participant + case_roles = participant.participant_roles - participant_flows.add_participant( - participant.individual.email, - incident, - db_session, - role=incident_role, - ) + # Map the case role to an incident role + incident_role = ParticipantRoleType.map_case_role_to_incident_role(case_roles) - # We add the participants to the conversation - conversation_flows.add_incident_participants_to_conversation( - db_session=db_session, - incident=incident, - participant_emails=[participant.individual.email], - ) + participant_flows.add_participant( + participant.individual.email, + incident, + db_session, + role=incident_role, + ) + + # We add the participants to the conversation + conversation_flows.add_incident_participants_to_conversation( + db_session=db_session, + incident=incident, + participant_emails=[participant.individual.email], + ) if case.has_channel: # depends on `incident_create_flow()` (we need incident.name), so we invoke after we call it