3434from dispatch .event import service as event_service
3535from dispatch .exceptions import ExistsError
3636from dispatch .individual .models import IndividualContactRead
37+ from dispatch .participant import flows as participant_flows
3738from dispatch .participant import service as participant_service
3839from dispatch .participant .models import ParticipantUpdate
3940from dispatch .participant_role import service as participant_role_service
7273 entity_select ,
7374 incident_priority_select ,
7475 incident_type_select ,
75- participant_select ,
7676 project_select ,
7777 relative_date_picker_input ,
7878 resolution_input ,
@@ -353,7 +353,6 @@ def handle_engage_user_command(
353353 """Handles engage user command."""
354354 ack ()
355355
356- case = case_service .get (db_session = db_session , case_id = context ["subject" ].id )
357356 default_engagement = "We'd like to verify your identity. Can you please confirm this is you?"
358357
359358 blocks = [
@@ -364,7 +363,7 @@ def handle_engage_user_command(
364363 )
365364 ]
366365 ),
367- participant_select (label = "Person to engage" , participants = case . participants ),
366+ assignee_select (label = "Person to engage" , placeholder = "Select user" ),
368367 description_input (label = "Engagement text" , initial_value = default_engagement ),
369368 ]
370369
@@ -402,14 +401,26 @@ def engage(
402401 """Handles the engage user action."""
403402 ack ()
404403
405- if form_data .get (DefaultBlockIds .participant_select ):
406- participant_id = form_data [DefaultBlockIds .participant_select ]["value" ]
407- participant = participant_service .get (db_session = db_session , participant_id = participant_id )
408- if participant :
409- user_email = participant .individual .email
410- else :
411- log .error (f"Participant not found for id { participant_id } when trying to engage user" )
412- return
404+ case = case_service .get (db_session = db_session , case_id = context ["subject" ].id )
405+ if not case :
406+ log .error ("Case not found when trying to engage user" )
407+ return
408+
409+ if form_data .get (DefaultBlockIds .case_assignee_select ):
410+ user_email = client .users_info (
411+ user = form_data [DefaultBlockIds .case_assignee_select ]["value" ]
412+ )["user" ]["profile" ]["email" ]
413+ conversation_flows .add_case_participants (case , [user_email ], db_session )
414+ participant = participant_service .get_by_case_id_and_email (
415+ db_session = db_session , case_id = case .id , email = user_email
416+ )
417+ if not participant :
418+ participant_flows .add_participant (
419+ user_email ,
420+ case ,
421+ db_session ,
422+ roles = [ParticipantRoleType .participant ],
423+ )
413424 else :
414425 return
415426
@@ -419,8 +430,6 @@ def engage(
419430 log .warning ("Engagement text not found" )
420431 return
421432
422- case = case_service .get (db_session = db_session , case_id = context ["subject" ].id )
423-
424433 user = client .users_lookupByEmail (email = user_email )
425434
426435 result = client .chat_postMessage (
@@ -1906,12 +1915,12 @@ def handle_resolve_submission_event(
19061915 case_id = updated_case .id ,
19071916 previous_case = previous_case ,
19081917 db_session = db_session ,
1909- reporter_email = updated_case . reporter . individual . email
1910- if updated_case .reporter
1911- else None ,
1912- assignee_email = updated_case . assignee . individual . email
1913- if updated_case .assignee
1914- else None ,
1918+ reporter_email = (
1919+ updated_case . reporter . individual . email if updated_case .reporter else None
1920+ ) ,
1921+ assignee_email = (
1922+ updated_case . assignee . individual . email if updated_case .assignee else None
1923+ ) ,
19151924 organization_slug = context ["subject" ].organization_slug ,
19161925 )
19171926 except Exception as e :
@@ -2423,6 +2432,9 @@ def handle_engagement_submission_event(
24232432 mfa_plugin = plugin_service .get_active_instance (
24242433 db_session = db_session , project_id = context ["subject" ].project_id , plugin_type = "auth-mfa"
24252434 )
2435+ if not mfa_plugin :
2436+ log .error ("Unable to engage user. No enabled MFA plugin found." )
2437+ return
24262438
24272439 require_mfa = engagement .require_mfa if engagement else True
24282440 mfa_enabled = True if mfa_plugin and require_mfa else False
@@ -2532,14 +2544,23 @@ def send_engagement_response(
25322544 if response == MfaChallengeStatus .APPROVED :
25332545 # We only update engagement message (which removes Confirm/Deny button) for success
25342546 # this allows the user to retry the confirmation if the MFA check failed
2535- blocks = create_signal_engagement_message (
2536- case = case ,
2537- channel_id = case .conversation .channel_id ,
2538- engagement = engagement ,
2539- signal_instance = signal_instance ,
2540- user_email = engaged_user ,
2541- engagement_status = engagement_status ,
2542- )
2547+ if not engagement :
2548+ # assume the message is from a manual MFA challenge
2549+ blocks = create_manual_engagement_message (
2550+ case = case ,
2551+ channel_id = case .conversation .channel_id ,
2552+ user_email = engaged_user ,
2553+ engagement_status = engagement_status ,
2554+ )
2555+ else :
2556+ blocks = create_signal_engagement_message (
2557+ case = case ,
2558+ channel_id = case .conversation .channel_id ,
2559+ engagement = engagement ,
2560+ signal_instance = signal_instance ,
2561+ user_email = engaged_user ,
2562+ engagement_status = engagement_status ,
2563+ )
25432564 if signal_instance :
25442565 client .chat_update (
25452566 blocks = blocks ,
0 commit comments