3232)
3333from dispatch .conversation import service as conversation_service
3434from dispatch .conversation .models import ConversationCreate
35+ from dispatch .database import SessionLocal
3536from dispatch .decorators import background_task
3637from dispatch .document import service as document_service
3738from dispatch .document .models import DocumentCreate
@@ -284,10 +285,15 @@ def update_incident_status(db_session, incident: Incident, status: str):
284285 log .debug (f"The incident has been marked as { status } ." )
285286
286287
287- def add_participant_to_conversation (conversation_id : str , participant_email : str ):
288+ def add_participant_to_conversation (
289+ participant_email : str , incident_id : int , db_session : SessionLocal
290+ ):
288291 """Adds a participant to the conversation."""
292+ # we load the incident instance
293+ incident = incident_service .get (db_session = db_session , incident_id = incident_id )
294+
289295 convo_plugin = plugins .get (INCIDENT_PLUGIN_CONVERSATION_SLUG )
290- convo_plugin .add (conversation_id , [participant_email ])
296+ convo_plugin .add (incident . conversation . channel_id , [participant_email ])
291297
292298
293299@background_task
@@ -326,7 +332,7 @@ def incident_create_flow(*, incident_id: int, checkpoint: str = None, db_session
326332 db_session = db_session , user_email = individual .email , incident_id = incident .id
327333 )
328334
329- log .debug (f"Added { len (individual_participants )} to incident." )
335+ log .debug (f"Added { len (individual_participants )} participants to incident id { incident . id } ." )
330336
331337 # create the incident ticket
332338 ticket = create_incident_ticket (
@@ -343,7 +349,6 @@ def incident_create_flow(*, incident_id: int, checkpoint: str = None, db_session
343349
344350 # we set the incident name
345351 name = ticket ["resource_id" ]
346-
347352 incident .name = name
348353
349354 log .debug ("Added name to incident." )
@@ -423,12 +428,11 @@ def incident_create_flow(*, incident_id: int, checkpoint: str = None, db_session
423428 weblink = conversation ["weblink" ],
424429 channel_id = conversation ["id" ],
425430 )
431+
426432 incident .conversation = conversation_service .create (
427433 db_session = db_session , conversation_in = conversation_in
428434 )
429435
430- log .debug ("Added conversation to incident." )
431-
432436 db_session .add (incident )
433437 db_session .commit ()
434438
@@ -472,12 +476,12 @@ def incident_create_flow(*, incident_id: int, checkpoint: str = None, db_session
472476 for participant in incident .participants :
473477 # we announce the participant in the conversation
474478 send_incident_participant_announcement_message (
475- participant .individual .email , incident , db_session
479+ participant .individual .email , incident . id , db_session
476480 )
477481
478482 # we send the welcome messages to the participant
479483 send_incident_welcome_participant_messages (
480- participant .individual .email , incident , db_session
484+ participant .individual .email , incident . id , db_session
481485 )
482486
483487 log .debug ("Sent incident welcome and announcement notifications." )
@@ -967,9 +971,6 @@ def incident_add_or_reactivate_participant_flow(
967971 user_email : str , incident_id : int , role : ParticipantRoleType = None , db_session = None
968972):
969973 """Runs the add or reactivate incident participant flow."""
970- # we load the incident instance
971- incident = incident_service .get (db_session = db_session , incident_id = incident_id )
972-
973974 # We get information about the individual
974975 contact_plugin = plugins .get (INCIDENT_PLUGIN_CONTACT_SLUG )
975976 individual_info = contact_plugin .get (user_email )
@@ -981,7 +982,6 @@ def incident_add_or_reactivate_participant_flow(
981982 if participant :
982983 if participant .is_active :
983984 log .debug (f"{ individual_info ['fullname' ]} is already an active participant." )
984- return
985985 else :
986986 # we reactivate the participant
987987 reactivated = participant_flows .reactivate_participant (
@@ -990,31 +990,31 @@ def incident_add_or_reactivate_participant_flow(
990990
991991 if reactivated :
992992 # we add the participant to the conversation
993- add_participant_to_conversation (incident . conversation . channel_id , user_email )
993+ add_participant_to_conversation (user_email , incident_id , db_session )
994994
995995 # we announce the participant in the conversation
996- send_incident_participant_announcement_message (user_email , incident , db_session )
996+ send_incident_participant_announcement_message (user_email , incident_id , db_session )
997997
998998 # we send the welcome messages to the participant
999- send_incident_welcome_participant_messages (user_email , incident , db_session )
1000-
1001- return
999+ send_incident_welcome_participant_messages (user_email , incident_id , db_session )
10021000 else :
10031001 # we add the participant to the incident
1004- added = participant_flows .add_participant (user_email , incident_id , db_session , role = role )
1002+ participant = participant_flows .add_participant (
1003+ user_email , incident_id , db_session , role = role
1004+ )
10051005
1006- if added :
1006+ if participant :
10071007 # we add the participant to the tactical group
10081008 add_participant_to_tactical_group (user_email , incident_id )
10091009
10101010 # we add the participant to the conversation
1011- add_participant_to_conversation (incident . conversation . channel_id , user_email )
1011+ add_participant_to_conversation (user_email , incident_id , db_session )
10121012
10131013 # we announce the participant in the conversation
1014- send_incident_participant_announcement_message (user_email , incident , db_session )
1014+ send_incident_participant_announcement_message (user_email , incident_id , db_session )
10151015
10161016 # we send the welcome messages to the participant
1017- send_incident_welcome_participant_messages (user_email , incident , db_session )
1017+ send_incident_welcome_participant_messages (user_email , incident_id , db_session )
10181018
10191019
10201020@background_task
@@ -1025,13 +1025,13 @@ def incident_remove_participant_flow(user_email: str, incident_id: int, db_sessi
10251025
10261026 if user_email == incident .commander .email :
10271027 # we add the incident commander to the conversation again
1028- add_participant_to_conversation (incident . conversation . channel_id , user_email )
1028+ add_participant_to_conversation (user_email , incident_id , db_session )
10291029
10301030 # we send a notification to the channel
1031- send_incident_commander_readded_notification (incident )
1031+ send_incident_commander_readded_notification (incident_id , db_session )
10321032
10331033 log .debug (
1034- f"Incident Commander { incident . commander . name } has been re-added to conversation { incident . conversation . channel_id } ."
1034+ f"Incident Commander with email { user_email } has been re-added to the incident conversation."
10351035 )
10361036 else :
10371037 # we remove the participant from the incident
0 commit comments