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

Bugfix/signal instance raw #3072

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
)
from slack_bolt import Ack, BoltContext, Respond
from slack_sdk.web.client import WebClient
from sqlalchemy.orm import Session
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session

from dispatch.auth.models import DispatchUser
from dispatch.case import flows as case_flows
Expand Down Expand Up @@ -71,7 +71,7 @@
from dispatch.project import service as project_service
from dispatch.search.utils import create_filter_expression
from dispatch.signal import service as signal_service
from dispatch.signal.models import SignalUpdate, SignalFilterCreate, SignalFilterRead
from dispatch.signal.models import SignalFilterCreate, SignalFilterRead, SignalUpdate


def configure(config: SlackConversationConfiguration):
Expand Down Expand Up @@ -1315,7 +1315,9 @@ def signal_button_click(
ack: Ack, body: dict, db_session: Session, context: BoltContext, client: WebClient
):
ack()
signal = signal_service.get(db_session=db_session, signal_id=context["subject"].id)
signal = signal_service.get_signal_instance(
db_session=db_session, signal_instance_id=context["subject"].id
)

blocks = [Section(text=f"```{json.dumps(signal.raw, indent=2)}```")]

Expand Down
14 changes: 13 additions & 1 deletion src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import json
from sqlalchemy_utils import cast_if

from datetime import datetime, timedelta, timezone
from typing import Optional, Literal

from pydantic.error_wrappers import ErrorWrapper, ValidationError
from sqlalchemy import asc
from sqlalchemy import asc, String
from sqlalchemy.orm import Session


from dispatch.auth.models import DispatchUser
from dispatch.case.priority import service as case_priority_service
from dispatch.case.type import service as case_type_service
Expand Down Expand Up @@ -118,6 +121,15 @@ def get_signal_filter(*, db_session: Session, signal_filter_id: int) -> SignalFi
return db_session.query(SignalFilter).filter(SignalFilter.id == signal_filter_id).one_or_none()


def get_signal_instance(*, db_session: Session, signal_instance_id: int | str):
"""Gets a signal instance by it's UUID."""
return (
db_session.query(SignalInstance)
.filter(SignalInstance.id == cast_if(signal_instance_id, String))
.one_or_none()
)


def get(*, db_session: Session, signal_id: int) -> Optional[Signal]:
"""Gets a signal by id."""
return db_session.query(Signal).filter(Signal.id == signal_id).one_or_none()
Expand Down