Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/editable-search-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
metroid-samus authored Aug 12, 2024
2 parents 57ad086 + 63741cf commit 21fb0ea
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 329 deletions.
12 changes: 7 additions & 5 deletions requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ aiocache==0.12.2
# via -r requirements-base.in
aiofiles==24.1.0
# via -r requirements-base.in
aiohttp==3.9.5
aiohappyeyeballs==2.3.5
# via aiohttp
aiohttp==3.10.2
# via -r requirements-base.in
aiosignal==1.3.1
# via aiohttp
Expand Down Expand Up @@ -124,7 +126,7 @@ frozenlist==1.4.1
# aiosignal
google-api-core==2.15.0
# via google-api-python-client
google-api-python-client==2.137.0
google-api-python-client==2.140.0
# via -r requirements-base.in
google-auth==2.26.1
# via
Expand Down Expand Up @@ -242,7 +244,7 @@ oauthlib[signedtoken]==3.2.2
# atlassian-python-api
# jira
# requests-oauthlib
openai==1.37.0
openai==1.39.0
# via -r requirements-base.in
packaging==23.2
# via
Expand Down Expand Up @@ -444,7 +446,7 @@ statsmodels==0.14.2
# via -r requirements-base.in
tabulate==0.9.0
# via -r requirements-base.in
tenacity==8.5.0
tenacity==9.0.0
# via -r requirements-base.in
text-unidecode==1.3
# via python-slugify
Expand Down Expand Up @@ -481,7 +483,7 @@ urllib3==2.0.7
# pdpyras
# requests
# sentry-sdk
uvicorn==0.30.3
uvicorn==0.30.5
# via -r requirements-base.in
uvloop==0.19.0
# via -r requirements-base.in
Expand Down
8 changes: 4 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ click==8.1.7
# via
# -r requirements-dev.in
# black
coverage==7.6.0
coverage==7.6.1
# via -r requirements-dev.in
decorator==5.1.1
# via ipython
Expand All @@ -32,7 +32,7 @@ executing==2.0.1
# stack-data
factory-boy==3.3.0
# via -r requirements-dev.in
faker==26.0.0
faker==26.3.0
# via
# -r requirements-dev.in
# factory-boy
Expand Down Expand Up @@ -68,7 +68,7 @@ platformdirs==4.1.0
# virtualenv
pluggy==1.3.0
# via pytest
pre-commit==3.7.1
pre-commit==3.8.0
# via -r requirements-dev.in
prompt-toolkit==3.0.43
# via ipython
Expand All @@ -86,7 +86,7 @@ python-dateutil==2.9.0.post0
# via faker
pyyaml==6.0.1
# via pre-commit
ruff==0.5.4
ruff==0.5.7
# via -r requirements-dev.in
six==1.16.0
# via
Expand Down
9 changes: 8 additions & 1 deletion src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ def case_status_transition_flow_dispatcher(
db_session: Session,
):
"""Runs the correct flows based on the current and previous status of the case."""
log.info(
"Transitioning Case status",
extra={"case_id": case.id, "previous_status": previous_status, "current_status": current_status}
)
match (previous_status, current_status):
case (CaseStatus.closed, CaseStatus.new):
# Closed -> New
Expand All @@ -568,7 +572,10 @@ def case_status_transition_flow_dispatcher(

case (_, CaseStatus.triage):
# Any -> Triage/
pass
log.warning(
"Unexpected previous state for Case transition to Triage state.",
extra={"case_id": case.id, "previous_status": previous_status, "current_status": current_status}
)

case (CaseStatus.new, CaseStatus.escalated):
# New -> Escalated
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/conversation/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def create_case_conversation(

conversation.update({"resource_type": plugin.plugin.slug, "resource_id": conversation["id"]})

print(f"got convo: {conversation}")
conversation_in = ConversationCreate(
resource_id=conversation["resource_id"],
resource_type=conversation["resource_type"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Adds lifecycle column to signal model
Revision ID: 71cd7ed999c4
Revises: ef17416626ff
Create Date: 2024-08-05 15:22:27.578399
"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "71cd7ed999c4"
down_revision = "ef17416626ff"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("signal", sa.Column("lifecycle", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("signal", "lifecycle")
# ### end Alembic commands ###
44 changes: 28 additions & 16 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,24 @@ def handle_update_case_command(
)
assignee_initial_user = None

statuses = [{"text": str(s), "value": str(s)} for s in CaseStatus if s != CaseStatus.escalated]

blocks = [
title_input(initial_value=case.title),
description_input(initial_value=case.description),
case_resolution_reason_select(optional=True),
resolution_input(initial_value=case.resolution),
assignee_select(initial_user=assignee_initial_user),
case_status_select(initial_option={"text": case.status, "value": case.status}),
case_status_select(
initial_option={"text": case.status, "value": case.status}, statuses=statuses
),
Context(
elements=[
MarkdownText(
text=f"Note: Cases cannot be escalated here. Please use the `{context['config'].slack_command_escalate_case}` slash command."
)
]
),
case_type_select(
db_session=db_session,
initial_option={"text": case.case_type.name, "value": case.case_type.id},
Expand Down Expand Up @@ -1206,20 +1217,6 @@ def handle_escalation_submission_event(
view=modal,
)

blocks = create_case_message(case=case, channel_id=context["subject"].channel_id)
if case.has_thread:
client.chat_update(
blocks=blocks,
ts=case.conversation.thread_id,
channel=case.conversation.channel_id,
)

client.chat_postMessage(
text="This case has been escalated to an incident. All further triage work will take place in the incident channel.",
channel=case.conversation.channel_id,
thread_ts=case.conversation.thread_id if case.has_thread else None,
)

incident_type = None
if form_data.get(DefaultBlockIds.incident_type_select):
incident_type = get_by_name(
Expand Down Expand Up @@ -1247,6 +1244,19 @@ def handle_escalation_submission_event(
)
incident = case.incidents[0]

blocks = create_case_message(case=case, channel_id=context["subject"].channel_id)
if case.has_thread:
client.chat_update(
blocks=blocks,
ts=case.conversation.thread_id,
channel=case.conversation.channel_id,
)
client.chat_postMessage(
text=f"This case has been escalated to incident {incident.name}. All further triage work will take place in the incident channel.",
channel=case.conversation.channel_id,
thread_ts=case.conversation.thread_id if case.has_thread else None,
)

# Retrieve all participants from the case
case_participants = case_service.get_participants(
db_session=db_session, case_id=case.id, minimal=True
Expand Down Expand Up @@ -1762,7 +1772,9 @@ def engagement_button_approve_click(
blocks.append(
Context(
elements=[
"After submission, you will be asked to confirm a Multi-Factor Authentication (MFA) prompt, please have your MFA device ready."
MarkdownText(
text="After submission, you will be asked to confirm a Multi-Factor Authentication (MFA) prompt, please have your MFA device ready."
)
]
),
)
Expand Down
7 changes: 5 additions & 2 deletions src/dispatch/plugins/dispatch_slack/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,14 @@ def case_status_select(
action_id: str = DefaultActionIds.case_status_select,
block_id: str = DefaultBlockIds.case_status_select,
label: str = "Status",
initial_option: dict = None,
initial_option: dict | None = None,
statuses: list[dict[str, str]] | None = None,
**kwargs,
):
"""Creates a case status select."""
statuses = [{"text": str(s), "value": str(s)} for s in CaseStatus]
if not statuses:
statuses = [{"text": str(s), "value": str(s)} for s in CaseStatus]

return static_select_block(
placeholder="Select Status",
options=statuses,
Expand Down
16 changes: 12 additions & 4 deletions src/dispatch/plugins/dispatch_slack/incident/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,12 @@ def handle_member_joined_channel(
)
participant.added_by = incident.commander

# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
if participant.added_by:
# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
else:
# We couldn't find a user to attribute the addition to, add generic reason
participant.added_reason = "Participant added by Dispatch"

db_session.add(participant)
db_session.commit()
Expand Down Expand Up @@ -1055,8 +1059,12 @@ def handle_member_joined_channel(
# We default to the incident commander when we don't know who added the user or the user is the Dispatch bot.
participant.added_by = case.assignee

# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
if participant.added_by:
# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
else:
# We couldn't find a user to attribute the addition to, add generic reason
participant.added_reason = "Participant added by Dispatch"

db_session.add(participant)
db_session.commit()
Expand Down
26 changes: 14 additions & 12 deletions src/dispatch/signal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class Signal(Base, TimeStampMixin, ProjectMixin):
create_case = Column(Boolean, default=True)
conversation_target = Column(String)
default = Column(Boolean, default=False)
lifecycle = Column(String)

oncall_service_id = Column(Integer, ForeignKey("service.id"))
oncall_service = relationship("Service", foreign_keys=[oncall_service_id])
Expand Down Expand Up @@ -311,6 +312,7 @@ class SignalBase(DispatchBase):
project: ProjectRead
source: Optional[SourceBase]
variant: Optional[str]
lifecycle: Optional[str]


class SignalCreate(SignalBase):
Expand Down Expand Up @@ -339,18 +341,18 @@ class SignalRead(SignalBase):
tags: Optional[List[TagRead]] = []


class SignalReadMinimal(DispatchBase):
id: PrimaryKey
name: str
owner: str
conversation_target: Optional[str]
description: Optional[str]
variant: Optional[str]
external_id: str
enabled: Optional[bool] = False
external_url: Optional[str]
create_case: Optional[bool] = True
created_at: Optional[datetime] = None
# class SignalReadMinimal(DispatchBase):
# id: PrimaryKey
# name: str
# owner: str
# conversation_target: Optional[str]
# description: Optional[str]
# variant: Optional[str]
# external_id: str
# enabled: Optional[bool] = False
# external_url: Optional[str]
# create_case: Optional[bool] = True
# created_at: Optional[datetime] = None


class SignalPagination(Pagination):
Expand Down
Loading

0 comments on commit 21fb0ea

Please sign in to comment.