예제 #1
0
파일: flows.py 프로젝트: Netflix/dispatch
def inactivate_participant(user_email: str, incident: Incident,
                           db_session: SessionLocal):
    """Inactivates a participant."""
    participant = get_by_incident_id_and_email(db_session=db_session,
                                               incident_id=incident.id,
                                               email=user_email)

    if not participant:
        log.debug(
            f"Can't inactivate participant with {user_email} email. They're not a participant of {incident.name} incident."
        )
        return False

    log.debug(
        f"Inactivating {participant.individual.name} from {incident.name} incident..."
    )

    participant_active_roles = participant_role_service.get_all_active_roles(
        db_session=db_session, participant_id=participant.id)
    for participant_active_role in participant_active_roles:
        participant_role_service.renounce_role(
            db_session=db_session, participant_role=participant_active_role)

    event_service.log(
        db_session=db_session,
        source="Dispatch Core App",
        description=f"{participant.individual.name} has been inactivated",
        incident_id=incident.id,
    )

    return True
예제 #2
0
파일: flows.py 프로젝트: terry-sm/dispatch
def remove_participant(user_email: str, incident_id: int,
                       db_session: SessionLocal):
    """Removes a participant."""
    # We load the incident
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    # We get information about the individual
    contact_plugin = plugin_service.get_active(db_session=db_session,
                                               plugin_type="contact")
    individual_info = contact_plugin.instance.get(user_email)
    individual_fullname = individual_info["fullname"]

    log.debug(
        f"Removing {individual_fullname} from incident {incident.name}...")

    participant = get_by_incident_id_and_email(db_session=db_session,
                                               incident_id=incident_id,
                                               email=user_email)

    if not participant:
        log.debug(
            f"Can't remove {individual_fullname}. They're not an active participant of incident {incident.name}."
        )
        return False

    # We mark the participant as inactive
    participant.is_active = False

    # We make the participant renounce to their active roles
    participant_active_roles = participant_role_service.get_all_active_roles(
        db_session=db_session, participant_id=participant.id)
    for participant_active_role in participant_active_roles:
        participant_role_service.renounce_role(
            db_session=db_session, participant_role=participant_active_role)

    # We add and commit the changes
    db_session.add(participant)
    db_session.commit()

    event_service.log(
        db_session=db_session,
        source="Dispatch Core App",
        description=f"{participant.individual.name} removed from incident",
        incident_id=incident_id,
    )

    return True
예제 #3
0
def remove_participant(user_email: str, incident_id: int,
                       db_session: SessionLocal):
    """Removes a participant."""
    # We load the incident
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    # We get information about the individual
    contact_plugin = plugins.get(INCIDENT_PLUGIN_CONTACT_SLUG)
    individual_info = contact_plugin.get(user_email)
    individual_fullname = individual_info["fullname"]

    log.debug(
        f"Removing {individual_fullname} from incident {incident.name}...")

    participant = get_by_incident_id_and_email(db_session=db_session,
                                               incident_id=incident_id,
                                               email=user_email)

    if not participant:
        log.debug(
            f"Can't remove {individual_fullname}. They're not an active participant of incident {incident.name}."
        )
        return False

    # We mark the participant as inactive
    participant.is_active = False

    # We make the participant renouce to their active roles
    participant_active_roles = participant_role_service.get_active_roles(
        db_session=db_session, participant_id=participant.id)

    for active_role in participant_active_roles:
        participant_role_service.renounce_role(db_session=db_session,
                                               participant_id=participant.id,
                                               role_type=active_role.role)

    # We add and commit the changes
    db_session.add(participant)
    db_session.commit()

    log.debug(
        f"Participant {participant.individual.name} has been removed from the incident."
    )

    return True
def test_renounce_role(session, participant_role):
    from dispatch.participant_role.service import renounce_role

    t_participant_role = renounce_role(db_session=session, participant_role=participant_role)
    assert t_participant_role.renounce_at