def test_add_role(session, participant, participant_role):
    from dispatch.participant_role.service import add_role

    t_participant_role = add_role(
        db_session=session, participant_id=participant.id, participant_role=participant_role.role
    )
    assert t_participant_role.participant_id == participant.id
    assert t_participant_role.role == participant_role.role
Example #2
0
def create(
    *,
    db_session,
    incident_priority: str,
    incident_type: str,
    reporter_email: str,
    title: str,
    status: str,
    description: str,
    visibility: str = None,
) -> Incident:
    """Creates a new incident."""
    # We get the incident type by name
    incident_type = incident_type_service.get_by_name(
        db_session=db_session, name=incident_type["name"])

    # We get the incident priority by name
    incident_priority = incident_priority_service.get_by_name(
        db_session=db_session, name=incident_priority["name"])

    if not visibility:
        visibility = incident_type.visibility

    # We create the incident
    incident = Incident(
        title=title,
        description=description,
        status=status,
        incident_type=incident_type,
        incident_priority=incident_priority,
        visibility=visibility,
    )
    db_session.add(incident)
    db_session.commit()

    event_service.log(
        db_session=db_session,
        source="Dispatch Core App",
        description="Incident created",
        incident_id=incident.id,
    )

    # We add the reporter to the incident
    reporter_participant = participant_flows.add_participant(
        reporter_email, incident.id, db_session, ParticipantRoleType.reporter)

    # We resolve the incident commander email
    incident_commander_email = resolve_incident_commander_email(
        db_session,
        reporter_email,
        incident_type.name,
        "",
        title,
        description,
        incident_priority.page_commander,
    )

    if reporter_email == incident_commander_email:
        # We add the role of incident commander the reporter
        participant_role_service.add_role(
            participant_id=reporter_participant.id,
            participant_role=ParticipantRoleType.incident_commander,
            db_session=db_session,
        )
    else:
        # We create a new participant for the incident commander and we add it to the incident
        participant_flows.add_participant(
            incident_commander_email,
            incident.id,
            db_session,
            ParticipantRoleType.incident_commander,
        )

    return incident
Example #3
0
def create(
    *,
    db_session,
    incident_priority: str,
    incident_type: str,
    reporter_email: str,
    title: str,
    status: str,
    description: str,
    tags: List[dict],
    visibility: str = None,
) -> Incident:
    """Creates a new incident."""
    # We get the incident type by name
    if not incident_type:
        incident_type = incident_type_service.get_default(
            db_session=db_session)
        if not incident_type:
            raise Exception(
                "No incident type specified and no default has been defined.")
    else:
        incident_type = incident_type_service.get_by_name(
            db_session=db_session, name=incident_type["name"])

    # We get the incident priority by name
    if not incident_priority:
        incident_priority = incident_priority_service.get_default(
            db_session=db_session)
        if not incident_priority:
            raise Exception(
                "No incident priority specified and no default has been defined."
            )
    else:
        incident_priority = incident_priority_service.get_by_name(
            db_session=db_session, name=incident_priority["name"])

    if not visibility:
        visibility = incident_type.visibility

    tag_objs = []
    for t in tags:
        tag_objs.append(
            tag_service.get_or_create(db_session=db_session,
                                      tag_in=TagCreate(**t)))

    # We create the incident
    incident = Incident(
        title=title,
        description=description,
        status=status,
        incident_type=incident_type,
        incident_priority=incident_priority,
        visibility=visibility,
        tags=tag_objs,
    )
    db_session.add(incident)
    db_session.commit()

    event_service.log(
        db_session=db_session,
        source="Dispatch Core App",
        description="Incident created",
        incident_id=incident.id,
    )

    # We add the reporter to the incident
    reporter_participant = participant_flows.add_participant(
        reporter_email, incident.id, db_session, ParticipantRoleType.reporter)

    # We resolve the incident commander email
    incident_commander_email = resolve_incident_commander_email(
        db_session,
        reporter_email,
        incident_type.name,
        "",
        title,
        description,
        incident_priority.page_commander,
    )

    if reporter_email == incident_commander_email:
        # We add the role of incident commander the reporter
        participant_role_service.add_role(
            participant_id=reporter_participant.id,
            participant_role=ParticipantRoleType.incident_commander,
            db_session=db_session,
        )
    else:
        # We create a new participant for the incident commander and we add it to the incident
        participant_flows.add_participant(
            incident_commander_email,
            incident.id,
            db_session,
            ParticipantRoleType.incident_commander,
        )

    return incident