def update_incident_from_submitted_form( user_id: str, user_email: str, channel_id: str, incident_id: int, action: dict, config: SlackConversationConfiguration = None, db_session=None, slack_client=None, ): """Massages slack dialog data into something that Dispatch can use.""" submitted_form = action.get("view") parsed_form_data = parse_submitted_form(submitted_form) incident = incident_service.get(db_session=db_session, incident_id=incident_id) 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) incident_in = IncidentUpdate( title=parsed_form_data[IncidentBlockId.title], description=parsed_form_data[IncidentBlockId.description], resolution=parsed_form_data[IncidentBlockId.resolution], incident_type={"name": parsed_form_data[IncidentBlockId.type]["value"]}, incident_priority={"name": parsed_form_data[IncidentBlockId.priority]["value"]}, status=parsed_form_data[IncidentBlockId.status]["value"], tags=tags, ) previous_incident = IncidentRead.from_orm(incident) # we don't allow visibility to be set in slack so we copy it over incident_in.visibility = incident.visibility updated_incident = incident_service.update( db_session=db_session, incident=incident, incident_in=incident_in ) commander_email = updated_incident.commander.individual.email reporter_email = updated_incident.reporter.individual.email incident_flows.incident_update_flow( user_email, commander_email, reporter_email, incident_id, previous_incident, db_session=db_session, ) if updated_incident.status != IncidentStatus.closed: send_ephemeral_message( slack_client, channel_id, user_id, "You have sucessfully updated the incident." )
def update_incident_from_submitted_form( user_id: str, user_email: str, channel_id: str, incident_id: int, action: dict, db_session=None, slack_client=None, ): """Massages slack dialog data into something that Dispatch can use.""" submitted_form = action.get("view") parsed_form_data = parse_submitted_form(submitted_form) tags = [] for t in parsed_form_data.get(IncidentBlockId.tags, []): tags.append({"id": t["value"]}) incident_in = IncidentUpdate( 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"]}, status=parsed_form_data[IncidentBlockId.status]["value"], tags=tags, ) incident = incident_service.get(db_session=db_session, incident_id=incident_id) existing_incident = IncidentRead.from_orm(incident) # we don't allow visibility to be set in slack so we copy it over incident_in.visibility = incident.visibility updated_incident = incident_service.update( db_session=db_session, incident=incident, incident_in=incident_in ) incident_flows.incident_update_flow( user_email, incident_id, existing_incident, db_session=db_session ) if updated_incident.status != IncidentStatus.closed: send_ephemeral_message( slack_client, channel_id, user_id, "You have sucessfully updated the incident." )