def create_report_incident_modal(command: dict = None, db_session=None): """ Prepare the Modal / View x Ask slack to open a modal with the prepared Modal / View content """ channel_id = command.get("channel_id") trigger_id = command.get("trigger_id") type_options = [] for t in incident_type_service.get_all(db_session=db_session): type_options.append({"label": t.name, "value": t.name}) priority_options = [] for priority in incident_priority_service.get_all(db_session=db_session): priority_options.append({ "label": priority.name, "value": priority.name }) modal_view_template = create_modal_content( channel_id=channel_id, incident_types=type_options, incident_priorities=priority_options) dispatch_slack_service.open_modal_with_user(client=slack_client, trigger_id=trigger_id, modal=modal_view_template)
def create_update_incident_dialog(incident_id: int, command: dict = None, db_session=None): """Creates a dialog for updating incident information.""" incident = incident_service.get(db_session=db_session, incident_id=incident_id) type_options = [] for t in incident_type_service.get_all(db_session=db_session): type_options.append({"label": t.name, "value": t.name}) priority_options = [] for priority in incident_priority_service.get_all(db_session=db_session): priority_options.append({"label": priority.name, "value": priority.name}) status_options = [] for status in IncidentStatus: status_options.append({"label": status.value, "value": status.value}) visibility_options = [] for visibility in Visibility: visibility_options.append({"label": visibility.value, "value": visibility.value}) notify_options = [{"label": "Yes", "value": "Yes"}, {"label": "No", "value": "No"}] dialog = { "callback_id": command["command"], "title": "Update Incident", "submit_label": "Save", "elements": [ {"type": "textarea", "label": "Title", "name": "title", "value": incident.title}, { "type": "textarea", "label": "Description", "name": "description", "value": incident.description, }, { "label": "Type", "type": "select", "name": "type", "value": incident.incident_type.name, "options": type_options, }, { "label": "Priority", "type": "select", "name": "priority", "value": incident.incident_priority.name, "options": priority_options, }, { "label": "Status", "type": "select", "name": "status", "value": incident.status, "options": status_options, }, { "label": "Visibility", "type": "select", "name": "visibility", "value": incident.visibility, "options": visibility_options, }, { "label": "Notify on change", "type": "select", "name": "notify", "value": "Yes", "options": notify_options, }, ], } dispatch_slack_service.open_dialog_with_user(slack_client, command["trigger_id"], dialog)
def test_get_all(session, project, incident_types): from dispatch.incident_type.service import get_all t_incident_types = get_all(db_session=session, project_id=incident_types[0].project.id).all() assert len(t_incident_types) >= 1
def build_report_incident_blocks(channel_id: str, db_session: Session): """Builds all blocks required for the reporting incident modal.""" incident_type_options = [] for incident_type in incident_type_service.get_all(db_session=db_session): incident_type_options.append( create_block_option_from_template(text=incident_type.name, value=incident_type.name)) incident_priority_options = [] for incident_priority in incident_priority_service.get_all( db_session=db_session): incident_priority_options.append( create_block_option_from_template(text=incident_priority.name, value=incident_priority.name)) modal_template = { "type": "modal", "title": { "type": "plain_text", "text": "Security Incident Report" }, "blocks": [ { "type": "context", "elements": [{ "type": "mrkdwn", "text": "If you suspect a security incident and require help from security, " "please fill out the following to the best of your abilities.", }], }, { "block_id": IncidentSlackViewBlockId.title, "type": "input", "label": { "type": "plain_text", "text": "Title" }, "element": { "type": "plain_text_input", "placeholder": { "type": "plain_text", "text": "A brief explanatory title. You can change this later.", }, }, }, { "block_id": IncidentSlackViewBlockId.description, "type": "input", "label": { "type": "plain_text", "text": "Description" }, "element": { "type": "plain_text_input", "placeholder": { "type": "plain_text", "text": "A summary of what you know so far. It's all right if this is incomplete.", }, "multiline": True, }, }, { "block_id": IncidentSlackViewBlockId.type, "type": "input", "label": { "type": "plain_text", "text": "Type" }, "element": { "type": "static_select", "placeholder": { "type": "plain_text", "text": "Select Incident Type" }, "options": incident_type_options, }, }, { "block_id": IncidentSlackViewBlockId.priority, "type": "input", "label": { "type": "plain_text", "text": "Priority", "emoji": True }, "element": { "type": "static_select", "placeholder": { "type": "plain_text", "text": "Select Incident Priority" }, "options": incident_priority_options, }, }, ], "close": { "type": "plain_text", "text": "Cancel" }, "submit": { "type": "plain_text", "text": "Submit" }, "callback_id": NewIncidentSubmission.form_slack_view, "private_metadata": json.dumps({"channel_id": str(channel_id)}), } return modal_template
def test_get_all(session, incident_type): from dispatch.incident_type.service import get_all t_incident_types = get_all(db_session=session).all() assert len(t_incident_types) > 1