Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slack): add signal snooze channel notification for visibility #5421

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 70 additions & 3 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
from dispatch.signal import service as signal_service
from dispatch.signal.enums import SignalEngagementStatus
from dispatch.signal.models import (
Signal,
SignalEngagement,
SignalFilter,
SignalFilterCreate,
SignalInstance,
)
Expand Down Expand Up @@ -843,14 +845,28 @@ def _create_snooze_filter(

signal.filters.append(new_filter)
db_session.commit()
return new_filter

channel_id = context["subject"].channel_id
thread_id = context["subject"].thread_id

# Check if last_mfa_time was within the last hour
if not mfa_enabled:
_create_snooze_filter(
new_filter = _create_snooze_filter(
db_session=db_session,
user=user,
subject=context["subject"],
)
signal = signal_service.get(db_session=db_session, signal_id=context["subject"].id)
post_snooze_message(
db_session=db_session,
client=client,
channel=channel_id,
user=user,
signal=signal,
new_filter=new_filter,
thread_ts=thread_id,
)
send_success_modal(
client=client,
view_id=body["view"]["id"],
Expand All @@ -875,12 +891,21 @@ def _create_snooze_filter(
)

if response == MfaChallengeStatus.APPROVED:
# Get the existing filters for the signal
_create_snooze_filter(
new_filter = _create_snooze_filter(
db_session=db_session,
user=user,
subject=context["subject"],
)
signal = signal_service.get(db_session=db_session, signal_id=context["subject"].id)
post_snooze_message(
db_session=db_session,
client=client,
channel=channel_id,
user=user,
signal=signal,
new_filter=new_filter,
thread_ts=thread_id,
)
send_success_modal(
client=client,
view_id=body["view"]["id"],
Expand Down Expand Up @@ -909,6 +934,48 @@ def _create_snooze_filter(
)


def post_snooze_message(
client: WebClient,
channel: str,
user: DispatchUser,
signal: Signal,
db_session: Session,
new_filter: SignalFilter,
thread_ts: str | None = None,
):
def extract_entity_ids(expression: list[dict]) -> list[int]:
entity_ids = []
for item in expression:
if isinstance(item, dict) and "or" in item:
for condition in item["or"]:
if condition.get("model") == "Entity" and condition.get("field") == "id":
entity_ids.append(int(condition.get("value")))
return entity_ids

entity_ids = extract_entity_ids(new_filter.expression)

if entity_ids:
entities = []
for entity_id in entity_ids:
entity = entity_service.get(db_session=db_session, entity_id=entity_id)
if entity:
entities.append(entity)
entities_text = ", ".join([f"{entity.value} ({entity.id})" for entity in entities])
else:
entities_text = "All"

message = (
f":zzz: *New Signal Snooze Added*\n"
f"• User: {user.email}\n"
f"• Signal: {signal.name}\n"
f"• Snooze Name: {new_filter.name}\n"
f"• Description: {new_filter.description}\n"
f"• Expiration: {new_filter.expiration}\n"
f"• Entities: {entities_text}"
)
client.chat_postMessage(channel=channel, text=message, thread_ts=thread_ts)


def assignee_select(
placeholder: str = "Select Assignee",
initial_user: str = None,
Expand Down
Loading