Beispiel #1
0
def incident_assign_role_flow(assigner_email: str,
                              incident_id: int,
                              assignee_email: str,
                              assignee_role: str,
                              db_session=None):
    """Runs the incident participant role assignment flow."""
    # we resolve the assigner and assignee's contact information
    contact_plugin = plugins.get(INCIDENT_PLUGIN_CONTACT_SLUG)
    assigner_contact_info = contact_plugin.get(assigner_email)
    assignee_contact_info = contact_plugin.get(assignee_email)

    # we load the incident instance
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    # we get the participant object for the assignee
    assignee_participant = participant_service.get_by_incident_id_and_email(
        db_session=db_session,
        incident_id=incident.id,
        email=assignee_contact_info["email"])

    if not assignee_participant:
        # The assignee is not a participant. We add them to the incident
        incident_add_or_reactivate_participant_flow(assignee_email,
                                                    incident.id,
                                                    db_session=db_session)

    # we run the participant assign role flow
    result = participant_role_flows.assign_role_flow(incident.id,
                                                     assignee_contact_info,
                                                     assignee_role, db_session)

    if result == "assignee_has_role":
        # NOTE: This is disabled until we can determine the source of the caller
        # we let the assigner know that the assignee already has this role
        # send_incident_participant_has_role_ephemeral_message(
        #    assigner_email, assignee_contact_info, assignee_role, incident
        # )
        return

    if result == "role_not_assigned":
        # NOTE: This is disabled until we can determine the source of the caller
        # we let the assigner know that we were not able to assign the role
        # send_incident_participant_role_not_assigned_ephemeral_message(
        #    assigner_email, assignee_contact_info, assignee_role, incident
        # )
        return

    if assignee_role != ParticipantRoleType.participant:
        # we send a notification to the incident conversation
        send_incident_new_role_assigned_notification(assigner_contact_info,
                                                     assignee_contact_info,
                                                     assignee_role, incident)

    if assignee_role == ParticipantRoleType.incident_commander:
        # we update the conversation topic
        set_conversation_topic(incident)

        # we update the external ticket
        update_external_incident_ticket(incident, db_session)
Beispiel #2
0
def incident_assign_role_flow(assigner_email: str,
                              incident_id: int,
                              action: dict,
                              db_session=None):
    """Runs the incident participant role assignment flow."""
    assignee_user_id = action["submission"]["participant"]
    assignee_role = action["submission"]["role"]

    # we resolve the assignee's email address
    convo_plugin = plugins.get(INCIDENT_PLUGIN_CONVERSATION_SLUG)
    assignee_email = convo_plugin.get_participant_email(assignee_user_id)

    # we resolve the assigner and assignee's contact information
    contact_plugin = plugins.get(INCIDENT_PLUGIN_CONTACT_SLUG)
    assigner_contact_info = contact_plugin.get(assigner_email)
    assignee_contact_info = contact_plugin.get(assignee_email)

    # we load the incident instance
    incident = incident_service.get(db_session=db_session,
                                    incident_id=incident_id)

    # we get the participant object for the assignee
    assignee_participant = participant_service.get_by_incident_id_and_email(
        db_session=db_session,
        incident_id=incident.id,
        email=assignee_contact_info["email"])

    if not assignee_participant:
        # The assignee is not a participant. We add them to the incident with the given role
        incident_add_or_reactivate_participant_flow(assignee_email,
                                                    incident.id,
                                                    db_session=db_session)

    # we run the participant assign role flow
    result = participant_role_flows.assign_role_flow(db_session, incident,
                                                     assignee_contact_info,
                                                     assignee_role)

    if result == "assignee_has_role":
        # we let the assigner know that the assignee already has this role
        send_incident_participant_has_role_ephemeral_message(
            assigner_email, assignee_contact_info, assignee_role, incident)
        return

    if result == "role_not_assigned":
        # we let the assigner know that we were not able to assign the role
        send_incident_participant_role_not_assigned_ephemeral_message(
            assigner_email, assignee_contact_info, assignee_role, incident)
        return

    if assignee_role != ParticipantRoleType.participant:
        # we send a notification to the incident conversation
        send_incident_new_role_assigned_notification(assigner_contact_info,
                                                     assignee_contact_info,
                                                     assignee_role, incident)

    if assignee_role == ParticipantRoleType.incident_commander:
        # we update the conversation topic
        set_conversation_topic(incident)

        # we get the incident document
        incident_document = get_document(
            db_session=db_session,
            incident_id=incident_id,
            resource_type=INCIDENT_RESOURCE_INVESTIGATION_DOCUMENT,
        )

        # we update the external ticket
        update_incident_ticket(
            incident.ticket.resource_id,
            description=incident.description,
            incident_type=incident.incident_type.name,
            commander_email=incident.commander.email,
            conversation_weblink=incident.conversation.weblink,
            document_weblink=incident_document.weblink,
            storage_weblink=incident.storage.weblink,
        )