Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/filter-not-showing-tags-in-counter
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Mar 4, 2024
2 parents 285dedc + d5db28d commit 0aeb165
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 64 deletions.
4 changes: 2 additions & 2 deletions requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ frozenlist==1.4.1
# aiosignal
google-api-core==2.15.0
# via google-api-python-client
google-api-python-client==2.119.0
google-api-python-client==2.120.0
# via -r requirements-base.in
google-auth==2.26.1
# via
Expand Down Expand Up @@ -320,7 +320,7 @@ pytest==7.4.4
# schemathesis
pytest-subtests==0.7.0
# via schemathesis
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via
# -r requirements-base.in
# botocore
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ identify==2.5.33
# via pre-commit
iniconfig==2.0.0
# via pytest
ipython==8.22.1
ipython==8.22.2
# via -r requirements-dev.in
jedi==0.19.1
# via ipython
Expand Down Expand Up @@ -82,11 +82,11 @@ pygments==2.17.2
# ipython
pytest==7.4.4
# via -r requirements-dev.in
python-dateutil==2.8.2
python-dateutil==2.9.0.post0
# via faker
pyyaml==6.0.1
# via pre-commit
ruff==0.2.2
ruff==0.3.0
# via -r requirements-dev.in
six==1.16.0
# via
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/plugins/dispatch_slack/case/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class CaseShortcutCallbacks(DispatchEnum):

class SignalNotificationActions(DispatchEnum):
snooze = "signal-notification-snooze"
view = "signal-notification-view"


class SignalSnoozeActions(DispatchEnum):
Expand Down
29 changes: 0 additions & 29 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,35 +1473,6 @@ def handle_report_submission_event(
)


@app.action(SignalNotificationActions.view, middleware=[button_context_middleware, db_middleware])
def signal_button_click(
ack: Ack, body: dict, db_session: Session, context: BoltContext, client: WebClient
):
ack()
signal = signal_service.get_signal_instance(
db_session=db_session, signal_instance_id=UUID(context["subject"].id)
)

# truncate text and redirect to ui
raw_text = json.dumps(signal.raw, indent=2)
if len(raw_text) > 2900:
blocks = [
Section(
text="The alert data exceeds Slack's viewing limit. Please go to the Dispatch Web UI for full details.\n"
),
Section(text=f"```{raw_text[:2750]}...```"),
]
else:
blocks = [Section(text=f"```{raw_text}```")]

modal = Modal(
title="Raw Signal",
blocks=blocks,
close="Close",
).build()
client.views_open(trigger_id=body["trigger_id"], view=modal)


@app.action(
SignalEngagementActions.approve,
middleware=[
Expand Down
5 changes: 0 additions & 5 deletions src/dispatch/plugins/dispatch_slack/case/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,6 @@ def create_signal_messages(case_id: int, channel_id: str, db_session: Session) -

# Define the initial elements with "Raw Data" and "Snooze" buttons
elements = [
Button(
text="Raw Data",
action_id=SignalNotificationActions.view,
value=button_metadata,
),
Button(
text="Snooze",
action_id=SignalNotificationActions.snooze,
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/plugins/dispatch_slack/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ class SlackAPIErrorCode(DispatchEnum):
VIEW_NOT_FOUND = "not_found" # Could not find corresponding view for the provided view_id
VIEW_EXPIRED = "expired_trigger_id" # The provided trigger_id is no longer valid
IS_ARCHIVED = "is_archived" # Channel is archived
MISSING_SCOPE = "missing_scope"
21 changes: 21 additions & 0 deletions src/dispatch/plugins/dispatch_slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
:license: Apache, see LICENSE for more details.
.. moduleauthor:: Kevin Glisson <[email protected]>
"""

from blockkit import Message
import io
import json
import logging
from typing import List, Optional, Any
from slack_sdk.errors import SlackApiError
from sqlalchemy.orm import Session

from dispatch.auth.models import DispatchUser
from dispatch.case.models import Case
from dispatch.config import DISPATCH_UI_URL
from dispatch.conversation.enums import ConversationCommands
from dispatch.decorators import apply, counter, timer
from dispatch.plugin import service as plugin_service
Expand Down Expand Up @@ -97,6 +101,23 @@ def create_threaded(self, case: Case, conversation_id: str, db_session: Session)
blocks=message,
)
case.signal_thread_ts = signal_response.get("timestamp")
try:
client.files_upload(
channels=conversation_id,
thread_ts=case.signal_thread_ts,
initial_comment=f"First alert in `{case.name}` (see all in <{DISPATCH_UI_URL}/{case.project.organization.slug}/cases/{case.name}|Dispatch UI>):",
filetype="json",
file=io.BytesIO(json.dumps(case.signal_instances[0].raw, indent=4).encode()),
)
except SlackApiError as e:
if e.response["error"] == SlackAPIErrorCode.MISSING_SCOPE:
logger.exception(
f"Error uploading alert JSON to the Case thread due to missing scope: {e}"
)
else:
logger.exception(f"Error uploading alert JSON to the Case thread: {e}")
except Exception as e:
logger.exception(f"Error uploading alert JSON to the Case thread: {e}")
db_session.commit()
return response

Expand Down
48 changes: 24 additions & 24 deletions src/dispatch/static/dispatch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0aeb165

Please sign in to comment.