Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 6df78fe

Browse files
authored
feat(slack): remove signal text from manual mfa engage and add user to channel (#5506)
1 parent 3cd2169 commit 6df78fe

File tree

2 files changed

+59
-38
lines changed

2 files changed

+59
-38
lines changed

src/dispatch/plugins/dispatch_slack/case/interactive.py

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from dispatch.event import service as event_service
3535
from dispatch.exceptions import ExistsError
3636
from dispatch.individual.models import IndividualContactRead
37+
from dispatch.participant import flows as participant_flows
3738
from dispatch.participant import service as participant_service
3839
from dispatch.participant.models import ParticipantUpdate
3940
from dispatch.participant_role import service as participant_role_service
@@ -72,7 +73,6 @@
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,

src/dispatch/plugins/dispatch_slack/case/messages.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -454,21 +454,20 @@ def create_signal_engagement_message(
454454
def create_manual_engagement_message(
455455
case: Case,
456456
channel_id: str,
457-
engagement: str,
458457
user_email: str,
459-
user_id: str,
460458
engagement_status: SignalEngagementStatus = SignalEngagementStatus.new,
459+
user_id: str = "",
460+
engagement: str = "",
461461
thread_ts: str = None,
462462
) -> list[Block]:
463463
"""
464-
Generate a list of blocks for a signal engagement message.
464+
Generate a list of blocks for a manual engagement message.
465465
466466
Args:
467-
case (Case): The case object related to the signal instance.
467+
case (Case): The case object related to the engagement.
468468
channel_id (str): The ID of the Slack channel where the message will be sent.
469-
message (str): Additional context information to include in the message.
469+
engagement_message (str): The engagement text.
470470
user_email (str): The email of the user being engaged.
471-
engagement (str): The engagement text.
472471
473472
Returns:
474473
list[Block]: A list of blocks representing the message structure for the engagement message.
@@ -486,11 +485,12 @@ def create_manual_engagement_message(
486485
).json()
487486

488487
username, _ = user_email.split("@")
489-
blocks = [
490-
Section(
491-
text=f"<@{user_id}>: {engagement if engagement else 'No context provided for this alert.'}"
492-
),
493-
]
488+
if engagement:
489+
blocks = [
490+
Section(text=f"<@{user_id}>: {engagement}"),
491+
]
492+
else:
493+
blocks = []
494494

495495
if engagement_status == SignalEngagementStatus.new:
496496
blocks.extend(

0 commit comments

Comments
 (0)