Esempio n. 1
0
def update_report_incident_modal(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict = None,
    db_session=None,
    slack_client=None,
):
    """Creates a modal for reporting an incident."""
    trigger_id = action["trigger_id"]

    submitted_form = action.get("view")
    parsed_form_data = parse_submitted_form(submitted_form)

    # we must pass existing values if they exist
    modal_update_template = report_incident(
        db_session=db_session,
        channel_id=channel_id,
        title=parsed_form_data[IncidentBlockId.title],
        description=parsed_form_data[IncidentBlockId.description],
        project_name=parsed_form_data[IncidentBlockId.project]["value"],
    )

    update_modal_with_user(
        client=slack_client,
        trigger_id=trigger_id,
        view_id=action["view"]["id"],
        modal=modal_update_template,
    )
Esempio n. 2
0
def update_update_participant_modal(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict,
    db_session=None,
    slack_client=None,
):
    """Pushes an updated view to the update participant modal."""
    trigger_id = action["trigger_id"]
    participant_id = action["actions"][0]["selected_option"]["value"]

    selected_participant = participant_service.get(
        db_session=db_session, participant_id=participant_id
    )
    incident = incident_service.get(db_session=db_session, incident_id=incident_id)

    modal_update_template = build_update_participant_blocks(
        incident=incident, participant=selected_participant
    )

    dispatch_slack_service.update_modal_with_user(
        client=slack_client,
        trigger_id=trigger_id,
        view_id=action["view"]["id"],
        modal=modal_update_template,
    )
Esempio n. 3
0
def update_update_participant_modal(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict,
    db_session=None,
    slack_client=None,
):
    """Pushes an updated view to the update participant modal."""
    trigger_id = action["trigger_id"]

    submitted_form = action.get("view")
    parsed_form_data = parse_submitted_form(submitted_form)

    participant_id = parsed_form_data[UpdateParticipantBlockId.participant]["value"]

    selected_participant = participant_service.get(
        db_session=db_session, participant_id=participant_id
    )
    incident = incident_service.get(db_session=db_session, incident_id=incident_id)
    modal_update_template = update_participant(incident=incident, participant=selected_participant)

    update_modal_with_user(
        client=slack_client,
        trigger_id=trigger_id,
        view_id=action["view"]["id"],
        modal=modal_update_template,
    )
Esempio n. 4
0
def update_workflow_modal(action: dict, db_session=None):
    """Pushes an updated view to the run workflow modal."""
    trigger_id = action["trigger_id"]
    incident_id = action["view"]["private_metadata"]["incident_id"]
    workflow_id = action["actions"][0]["selected_option"]["value"]

    selected_workflow = workflow_service.get(db_session=db_session,
                                             workflow_id=workflow_id)
    workflows = workflow_service.get_enabled(db_session=db_session)
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    modal_template = build_workflow_blocks(incident=incident,
                                           workflows=workflows,
                                           selected_workflow=selected_workflow)

    modal_template["blocks"].append(
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": f"*Description* \n {selected_workflow.description}"
            },
        }, )

    modal_template["blocks"].append(
        {
            "block_id": RunWorkflowBlockFields.run_reason,
            "type": "input",
            "element": {
                "type": "plain_text_input",
                "multiline": True,
                "action_id": RunWorkflowBlockFields.run_reason,
            },
            "label": {
                "type": "plain_text",
                "text": "Run Reason"
            },
        }, )

    modal_template["blocks"].append({
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "*Parameters*"
        }
    })

    if selected_workflow.parameters:
        for p in selected_workflow.parameters:
            modal_template["blocks"].append({
                "block_id": f"{RunWorkflowBlockFields.param}-{p['key']}",
                "type": "input",
                "element": {
                    "type": "plain_text_input",
                    "placeholder": {
                        "type": "plain_text",
                        "text": "Value"
                    },
                },
                "label": {
                    "type": "plain_text",
                    "text": p["key"]
                },
            })

    else:
        modal_template["blocks"].append({
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "This workflow has no parameters."
            },
        })

    modal_template["callback_id"] = RunWorkflowCallbacks.submit_form

    dispatch_slack_service.update_modal_with_user(
        client=slack_client,
        trigger_id=trigger_id,
        view_id=action["view"]["id"],
        modal=modal_template,
    )