def incident_add_or_reactivate_participant_flow( user_email: str, incident_id: int, role: ParticipantRoleType = None, event: dict = None, db_session=None, ) -> Participant: """Runs the add or reactivate incident participant flow.""" participant = participant_service.get_by_incident_id_and_email( db_session=db_session, incident_id=incident_id, email=user_email) if participant: if participant.is_active: log.debug(f"{user_email} is already an active participant.") else: # we reactivate the participant reactivated = participant_flows.reactivate_participant( user_email, incident_id, db_session) if reactivated: # we add the participant to the conversation add_participant_to_conversation(user_email, incident_id, db_session) # we announce the participant in the conversation send_incident_participant_announcement_message( user_email, incident_id, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages( user_email, incident_id, db_session) else: # we add the participant to the incident participant = participant_flows.add_participant(user_email, incident_id, db_session, role=role) # we add the participant to the tactical group add_participant_to_tactical_group(user_email, incident_id, db_session) # we add the participant to the conversation add_participant_to_conversation(user_email, incident_id, db_session) # we announce the participant in the conversation send_incident_participant_announcement_message(user_email, incident_id, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages(user_email, incident_id, db_session) # we send a suggested reading message to the participant suggested_document_items = get_suggested_document_items( incident_id, db_session) send_incident_suggested_reading_messages(incident_id, suggested_document_items, user_email, db_session) return participant
def incident_add_or_reactivate_participant_flow( user_email: str, incident_id: int, role: ParticipantRoleType = None, db_session=None ): """Runs the add or reactivate incident participant flow.""" # we load the incident instance 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) participant = participant_service.get_by_incident_id_and_email( db_session=db_session, incident_id=incident_id, email=user_email ) if participant: if participant.is_active: log.debug(f"{individual_info['fullname']} is already an active participant.") return else: # we reactivate the participant reactivated = participant_flows.reactivate_participant( user_email, incident_id, db_session ) if reactivated: # we add the participant to the conversation add_participant_to_conversation(incident.conversation.channel_id, user_email) # we announce the participant in the conversation send_incident_participant_announcement_message(user_email, incident, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages(user_email, incident, db_session) return else: # we add the participant to the incident added = participant_flows.add_participant(user_email, incident_id, db_session, role=role) if added: # we add the participant to the tactical group add_participant_to_tactical_group(user_email, incident_id) # we add the participant to the conversation add_participant_to_conversation(incident.conversation.channel_id, user_email) # we announce the participant in the conversation send_incident_participant_announcement_message(user_email, incident, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages(user_email, incident, db_session)
def incident_add_or_reactivate_participant_flow( user_email: str, incident_id: int, service: Service = None, role: ParticipantRoleType = None, event: dict = None, db_session=None, ) -> Participant: """Runs the add or reactivate incident participant flow.""" if service: # we need to ensure that we don't add another member of a service if one # already exists (e.g. overlapping oncalls, we assume they will hand-off if necessary) participant = participant_service.get_by_incident_id_and_service( incident_id=incident_id, service_id=service.id, db_session=db_session ) if participant: log.debug("Skipping resolved participant, service member already engaged.") return participant = participant_service.get_by_incident_id_and_email( db_session=db_session, incident_id=incident_id, email=user_email ) if participant: if participant.is_active: log.debug(f"{user_email} is already an active participant.") else: # we reactivate the participant reactivated = participant_flows.reactivate_participant( user_email, incident_id, db_session ) if reactivated: # we add the participant to the conversation add_participants_to_conversation([user_email], incident_id, db_session) # we announce the participant in the conversation send_incident_participant_announcement_message(user_email, incident_id, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages(user_email, incident_id, db_session) else: # we add the participant to the incident participant = participant_flows.add_participant( user_email, incident_id, db_session, service=service, role=role ) # we add the participant to the tactical group add_participant_to_tactical_group(user_email, incident_id, db_session) # we add the participant to the conversation add_participants_to_conversation([user_email], incident_id, db_session) # we announce the participant in the conversation send_incident_participant_announcement_message(user_email, incident_id, db_session) # we send the welcome messages to the participant send_incident_welcome_participant_messages(user_email, incident_id, db_session) # we send a suggested reading message to the participant suggested_document_items = get_suggested_document_items(incident_id, db_session) send_incident_suggested_reading_messages( incident_id, suggested_document_items, user_email, db_session ) return participant