Exemple #1
0
def update_participant_from_submitted_form(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict,
    db_session=None,
    slack_client=None,
):
    """Saves form data."""
    submitted_form = action.get("view")

    parsed_form_data = parse_submitted_form(submitted_form)

    added_reason = parsed_form_data.get(UpdateParticipantBlockFields.reason_added)
    participant_id = int(parsed_form_data.get(UpdateParticipantBlockFields.participant)["value"])
    selected_participant = participant_service.get(
        db_session=db_session, participant_id=participant_id
    )
    participant_service.update(
        db_session=db_session,
        participant=selected_participant,
        participant_in=ParticipantUpdate(added_reason=added_reason),
    )

    dispatch_slack_service.send_ephemeral_message(
        client=slack_client,
        conversation_id=channel_id,
        user_id=user_id,
        text="You have successfully updated the participant.",
    )
Exemple #2
0
def create_incident(
    *,
    db_session: Session = Depends(get_db),
    organization: OrganizationSlug,
    incident_in: IncidentCreate,
    current_user: DispatchUser = Depends(get_current_user),
    background_tasks: BackgroundTasks,
):
    """Create a new incident."""
    if not incident_in.reporter:
        incident_in.reporter = ParticipantUpdate(
            individual=IndividualContactRead(email=current_user.email)
        )
    incident = create(db_session=db_session, incident_in=incident_in)

    if incident.status == IncidentStatus.stable:
        background_tasks.add_task(
            incident_create_stable_flow, incident_id=incident.id, organization_slug=organization
        )
    elif incident.status == IncidentStatus.closed:
        background_tasks.add_task(
            incident_create_closed_flow, incident_id=incident.id, organization_slug=organization
        )
    else:
        background_tasks.add_task(
            incident_create_flow, incident_id=incident.id, organization_slug=organization
        )

    return incident
Exemple #3
0
def report_incident_from_submitted_form(
    user_id: str,
    user_email: str,
    channel_id: str,
    incident_id: int,
    action: dict,
    config: SlackConversationConfiguration = None,
    db_session: SessionLocal = None,
    slack_client=None,
):
    submitted_form = action.get("view")
    parsed_form_data = parse_submitted_form(submitted_form)

    # Send a confirmation to the user
    blocks = create_incident_reported_confirmation_message(
        title=parsed_form_data[IncidentBlockId.title],
        description=parsed_form_data[IncidentBlockId.description],
        incident_type=parsed_form_data[IncidentBlockId.type]["value"],
        incident_priority=parsed_form_data[IncidentBlockId.priority]["value"],
    )

    send_ephemeral_message(
        client=slack_client,
        conversation_id=channel_id,
        user_id=user_id,
        text="",
        blocks=blocks,
    )

    tags = []
    for t in parsed_form_data.get(IncidentBlockId.tags, []):
        # we have to fetch as only the IDs are embedded in slack
        tag = tag_service.get(db_session=db_session, tag_id=int(t["value"]))
        tags.append(tag)

    project = {"name": parsed_form_data[IncidentBlockId.project]["value"]}
    incident_in = IncidentCreate(
        title=parsed_form_data[IncidentBlockId.title],
        description=parsed_form_data[IncidentBlockId.description],
        incident_type={"name": parsed_form_data[IncidentBlockId.type]["value"]},
        incident_priority={"name": parsed_form_data[IncidentBlockId.priority]["value"]},
        project=project,
        tags=tags,
    )

    if not incident_in.reporter:
        incident_in.reporter = ParticipantUpdate(individual=IndividualContactRead(email=user_email))

    # Create the incident
    incident = incident_service.create(db_session=db_session, incident_in=incident_in)

    incident_flows.incident_create_flow(
        incident_id=incident.id,
        db_session=db_session,
        organization_slug=incident.project.organization.slug,
    )
Exemple #4
0
def test_update(session, participant):
    from dispatch.participant.service import update
    from dispatch.participant.models import ParticipantUpdate

    location = "Updated location"

    participant_in = ParticipantUpdate(location=location)
    participant = update(db_session=session,
                         participant=participant,
                         participant_in=participant_in)
    assert participant.location == location
Exemple #5
0
def update_participant_from_submitted_form(action: dict, db_session=None):
    """Saves form data."""
    submitted_form = action.get("view")

    parsed_form_data = parse_submitted_form(submitted_form)

    added_reason = parsed_form_data.get(
        UpdateParticipantBlockFields.reason_added)
    participant_id = int(
        parsed_form_data.get(
            UpdateParticipantBlockFields.participant)["value"])
    selected_participant = participant_service.get(
        db_session=db_session, participant_id=participant_id)
    participant_service.update(
        db_session=db_session,
        participant=selected_participant,
        participant_in=ParticipantUpdate(added_reason=added_reason),
    )