Skip to content

Commit

Permalink
More work on workflow syncing.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss committed Sep 25, 2020
1 parent f3bd695 commit f07d2a5
Show file tree
Hide file tree
Showing 16 changed files with 405 additions and 110 deletions.
28 changes: 28 additions & 0 deletions src/dispatch/alembic/versions/9f927a8e4679_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""empty message
Revision ID: 9f927a8e4679
Revises: 995a59897e01
Create Date: 2020-09-25 12:48:21.180604
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9f927a8e4679'
down_revision = '995a59897e01'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('workflow_instance', sa.Column('parameters', sa.JSON(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('workflow_instance', 'parameters')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions src/dispatch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def dispatch_scheduler():
from .tag.scheduled import sync_tags # noqa
from .task.scheduled import sync_tasks, create_task_reminders # noqa
from .term.scheduled import sync_terms # noqa
from .workflow.scheduled import sync_workflows, sync_active_stable_workflows # noqa


@dispatch_scheduler.command("list")
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def primary_location(self):
tasks = relationship("Task", backref="incident")
terms = relationship("Term", secondary=assoc_incident_terms, backref="incidents")
ticket = relationship("Ticket", uselist=False, backref="incident")
workflow_instances = relationship("WorkflowInstance", backref="incident")

# allow incidents to be marked as duplicate
duplicate_id = Column(Integer, ForeignKey("incident.id"))
Expand Down
11 changes: 11 additions & 0 deletions src/dispatch/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class MessageType(str, Enum):
INCIDENT_TASK_RESOLVED_DESCRIPTION = """
The following incident task has been resolved in the incident document.\n\n*Description:* {{task_description}}\n\n*Assignees:* {{task_assignees|join(',')}}"""

INCIDENT_WORKFLOW_UPDATE_DESCRIPTION = """
The following workflow has changed from *{{ instance_status_old }}* to *{{ instance_status_new }}*."""

INCIDENT_TYPE_CHANGE_DESCRIPTION = """
The incident type has been changed from *{{ incident_type_old }}* to *{{ incident_type_new }}*."""

Expand Down Expand Up @@ -448,6 +451,14 @@ class MessageType(str, Enum):
}
]

INCIDENT_WORKFLOW_UPDATE_NOTIFICATION = [
{
"title": "Workflow Status Update",
"title_link": "{{workflow_weblink}}",
"text": INCIDENT_WORKFLOW_UPDATE_DESCRIPTION,
}
]

INCIDENT_COMMANDER_READDED_NOTIFICATION = [
{"title": "Incident Commander Re-Added", "text": INCIDENT_COMMANDER_READDED_DESCRIPTION}
]
Expand Down
9 changes: 1 addition & 8 deletions src/dispatch/plugins/dispatch_slack/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
SLACK_COMMAND_REPORT_EXECUTIVE_SLUG,
SLACK_COMMAND_REPORT_TACTICAL_SLUG,
SLACK_COMMAND_UPDATE_INCIDENT_SLUG,
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG,
SLACK_COMMAND_RUN_WORKFLOW_SLUG,
)

from .service import get_user_email
Expand Down Expand Up @@ -127,12 +127,6 @@ def handle_assign_role_action(user_id, user_email, incident_id, action, db_sessi
incident_flows.incident_assign_role_flow(user_email, incident_id, assignee_email, assignee_role)


@background_task
def handle_run_external_flow_action(user_id, user_email, incident_id, action, db_session=None):
"""Massages slack dialog data into something that Dispatch can use."""
pass


def dialog_action_functions(action: str):
"""Interprets the action and routes it to the appropriate function."""
action_mappings = {
Expand All @@ -141,7 +135,6 @@ def dialog_action_functions(action: str):
SLACK_COMMAND_REPORT_EXECUTIVE_SLUG: [report_flows.create_executive_report],
SLACK_COMMAND_REPORT_TACTICAL_SLUG: [report_flows.create_tactical_report],
SLACK_COMMAND_UPDATE_INCIDENT_SLUG: [handle_update_incident_action],
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG: [handle_run_external_flow_action],
}

# this allows for unique action blocks e.g. invite-user or invite-user-1, etc
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch/plugins/dispatch_slack/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
SLACK_COMMAND_UPDATE_NOTIFICATIONS_GROUP_SLUG,
SLACK_COMMAND_UPDATE_PARTICIPANT_SLUG,
SLACK_COMMAND_ADD_TIMELINE_EVENT_SLUG,
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG,
SLACK_COMMAND_RUN_WORKFLOW_SLUG,
)

from .modals import (
create_add_timeline_event_modal,
create_report_incident_modal,
create_update_notifications_group_modal,
create_update_participant_modal,
create_run_external_workflow_modal,
create_run_workflow_modal,
)

from .dialogs import (
Expand Down Expand Up @@ -63,7 +63,7 @@ def command_functions(command: str):
SLACK_COMMAND_UPDATE_INCIDENT_SLUG: [create_update_incident_dialog],
SLACK_COMMAND_UPDATE_NOTIFICATIONS_GROUP_SLUG: [create_update_notifications_group_modal],
SLACK_COMMAND_UPDATE_PARTICIPANT_SLUG: [create_update_participant_modal],
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG: [create_run_external_workflow_modal],
SLACK_COMMAND_RUN_WORKFLOW_SLUG: [create_run_workflow_modal],
}

return command_mappings.get(command, [])
Expand Down
5 changes: 2 additions & 3 deletions src/dispatch/plugins/dispatch_slack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
SLACK_COMMAND_ADD_TIMELINE_EVENT_SLUG = config(
"SLACK_COMMAND_ADD_TIMELINE_EVENT_SLUG", default="/dispatch-add-timeline-event"
)

SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG = config(
"SLACK_RUN_EXTERNAL_COMMAND_WORKFLOW_SLUG", default="/dispatch-run-external-workflow"
SLACK_COMMAND_RUN_WORKFLOW_SLUG = config(
"SLACK_RUN_COMMAND_WORKFLOW_SLUG", default="/dispatch-run-workflow"
)
6 changes: 3 additions & 3 deletions src/dispatch/plugins/dispatch_slack/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
SLACK_COMMAND_UPDATE_INCIDENT_SLUG,
SLACK_COMMAND_UPDATE_NOTIFICATIONS_GROUP_SLUG,
SLACK_COMMAND_UPDATE_PARTICIPANT_SLUG,
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG,
SLACK_COMMAND_RUN_WORKFLOW_SLUG,
)


Expand All @@ -40,9 +40,9 @@
INCIDENT_CONVERSATION_TACTICAL_REPORT_SUGGESTION = f"Consider providing a tactical report using the `{SLACK_COMMAND_REPORT_TACTICAL_SLUG}` command."

INCIDENT_CONVERSATION_COMMAND_MESSAGE = {
SLACK_COMMAND_RUN_EXTERNAL_WORKFLOW_SLUG: {
SLACK_COMMAND_RUN_WORKFLOW_SLUG: {
"response_type": "ephemeral",
"text": "Opening a modal to run an external workflow...",
"text": "Opening a modal to run a workflow...",
},
SLACK_COMMAND_REPORT_TACTICAL_SLUG: {
"response_type": "ephemeral",
Expand Down

0 comments on commit f07d2a5

Please sign in to comment.