Skip to content

Commit

Permalink
Updates Slack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilanova committed Feb 16, 2022
1 parent 0e214af commit 7885f9b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/dispatch/plugins/dispatch_slack/modals/incident/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

# report + update blocks
class IncidentBlockId(DispatchEnum):
title = "title_field"
description = "description_field"
type = "incident_type_field"
priority = "incident_priority_field"
tags = "tags_select_field"
project = "project_field"
resolution = "resolution_field"
status = "status_field"
tags = "tags_select_field"
title = "title_field"
type = "incident_type_field"


# report incident
Expand Down
27 changes: 25 additions & 2 deletions src/dispatch/plugins/dispatch_slack/modals/incident/fields.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import logging
from typing import List

from sqlalchemy.orm import Session
from dispatch.incident.enums import IncidentStatus

from dispatch.incident.enums import IncidentStatus
from dispatch.incident.models import Incident
from dispatch.incident_priority import service as incident_priority_service
from dispatch.incident_priority.models import IncidentPriority
from dispatch.incident_type import service as incident_type_service
from dispatch.incident_type.models import IncidentType
from dispatch.participant.models import Participant
from dispatch.tag.models import Tag
from dispatch.project import service as project_service
from dispatch.tag.models import Tag

from .enums import (
IncidentBlockId,
Expand Down Expand Up @@ -224,6 +225,28 @@ def description_input_block(initial_value: str = None):
return block


def resolution_input_block(initial_value: str = None):
"""Builds a valid incident resolution input."""
block = {
"block_id": IncidentBlockId.resolution,
"type": "input",
"label": {"type": "plain_text", "text": "Resolution"},
"element": {
"type": "plain_text_input",
"placeholder": {
"type": "plain_text",
"text": "Description of the actions taken to resolve the incident.",
},
"multiline": True,
},
}

if initial_value:
block["element"].update({"initial_value": initial_value})

return block


def participants_select_block(incident: Incident, initial_option: Participant = None):
"""Builds a static select with all current participants."""
participant_options = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def update_incident_from_submitted_form(
incident_in = IncidentUpdate(
title=parsed_form_data[IncidentBlockId.title],
description=parsed_form_data[IncidentBlockId.description],
resolution=parsed_form_data[IncidentBlockId.resolution],
incident_type={"name": parsed_form_data[IncidentBlockId.type]["value"]},
incident_priority={"name": parsed_form_data[IncidentBlockId.priority]["value"]},
status=parsed_form_data[IncidentBlockId.status]["value"],
Expand Down
26 changes: 14 additions & 12 deletions src/dispatch/plugins/dispatch_slack/modals/incident/views.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
import json

from dispatch.database.core import SessionLocal
from dispatch.incident.models import Incident
from dispatch.incident import service as incident_service
from dispatch.incident.models import Incident
from dispatch.participant.models import Participant
from dispatch.project import service as project_service
from dispatch.plugin import service as plugin_service

from dispatch.project import service as project_service

from .enums import (
AddTimelineEventBlockId,
AddTimelineEventCallbackId,
ReportIncidentCallbackId,
UpdateIncidentCallbackId,
UpdateParticipantCallbackId,
UpdateNotificationsGroupBlockId,
UpdateNotificationsGroupCallbackId,
AddTimelineEventCallbackId,
UpdateParticipantBlockId,
UpdateNotificationsGroupBlockId,
AddTimelineEventBlockId,
UpdateParticipantCallbackId,
)

from .fields import (
option_from_template,
title_input_block,
description_input_block,
project_select_block,
participants_select_block,
status_select_block,
incident_priority_select_block,
incident_type_select_block,
option_from_template,
participants_select_block,
project_select_block,
resolution_input_block,
status_select_block,
tag_multi_select_block,
title_input_block,
)


Expand All @@ -50,6 +51,7 @@ def update_incident(db_session: SessionLocal, channel_id: str, incident_id: int
},
title_input_block(initial_value=incident.title),
description_input_block(initial_value=incident.description),
resolution_input_block(initial_value=incident.resolution),
status_select_block(initial_option=incident.status),
incident_type_select_block(
db_session=db_session,
Expand Down

0 comments on commit 7885f9b

Please sign in to comment.