def update(*, db_session, incident_type: IncidentType, incident_type_in: IncidentTypeUpdate) -> IncidentType: """Updates an incident type.""" if incident_type_in.incident_template_document: incident_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.incident_template_document.id) incident_type.incident_template_document = incident_template_document if incident_type_in.executive_template_document: executive_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.executive_template_document.id) incident_type.executive_template_document = executive_template_document if incident_type_in.review_template_document: review_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.review_template_document.id) incident_type.review_template_document = review_template_document if incident_type_in.tracking_template_document: tracking_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.tracking_template_document.id) incident_type.tracking_template_document = tracking_template_document if incident_type_in.commander_service: commander_service = service_service.get( db_session=db_session, service_id=incident_type_in.commander_service.id) incident_type.commander_service = commander_service if incident_type_in.liaison_service: liaison_service = service_service.get( db_session=db_session, service_id=incident_type_in.liaison_service.id) incident_type.liaison_service = liaison_service incident_type_data = incident_type.dict() update_data = incident_type_in.dict( skip_defaults=True, exclude={ "commander_service", "liaison_service", "incident_template_document", "executive_template_document", "tracking_template_document", "review_template_document", }, ) for field in incident_type_data: if field in update_data: setattr(incident_type, field, update_data[field]) db_session.commit() return incident_type
def create(*, db_session, incident_type_in: IncidentTypeCreate) -> IncidentType: """Creates an incident type.""" project = project_service.get_by_name_or_raise( db_session=db_session, project_in=incident_type_in.project) incident_type = IncidentType( **incident_type_in.dict( exclude={ "commander_service", "incident_template_document", "executive_template_document", "tracking_template_document", "review_template_document", "project", }), project=project, ) if incident_type_in.incident_template_document: incident_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.incident_template_document.id) incident_type.incident_template_document = incident_template_document if incident_type_in.executive_template_document: executive_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.executive_template_document.id) incident_type.executive_template_document = executive_template_document if incident_type_in.review_template_document: review_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.review_template_document.id) incident_type.review_template_document = review_template_document if incident_type_in.tracking_template_document: tracking_template_document = document_service.get( db_session=db_session, document_id=incident_type_in.tracking_template_document.id) incident_type.tracking_template_document = tracking_template_document if incident_type_in.commander_service: commander_service = service_service.get( db_session=db_session, service_id=incident_type_in.commander_service.id) incident_type.commander_service = commander_service if incident_type_in.liaison_service: liaison_service = service_service.get( db_session=db_session, service_id=incident_type_in.liaison_service.id) incident_type.liaison_service = liaison_service db_session.add(incident_type) db_session.commit() return incident_type
def update(*, db_session, incident_type: IncidentType, incident_type_in: IncidentTypeUpdate) -> IncidentType: """Updates an incident type.""" if incident_type_in.template_document: template_document = document_service.get( db_session=db_session, document_id=incident_type_in.template_document.id) incident_type.template_document = template_document if incident_type_in.commander_service: commander_service = service_service.get( db_session=db_session, service_id=incident_type_in.commander_service.id) incident_type.commander_service = commander_service incident_type_data = jsonable_encoder(incident_type) update_data = incident_type_in.dict( skip_defaults=True, exclude={"commander_service", "template_document"}) for field in incident_type_data: if field in update_data: setattr(incident_type, field, update_data[field]) db_session.add(incident_type) db_session.commit() return incident_type
def create(*, db_session, incident_type_in: IncidentTypeCreate) -> IncidentType: """Creates an incident type.""" project = project_service.get_by_name(db_session=db_session, name=incident_type_in.project.name) incident_type = IncidentType( **incident_type_in.dict( exclude={"commander_service", "template_document", "project"}), project=project, ) if incident_type_in.template_document: template_document = document_service.get( db_session=db_session, document_id=incident_type_in.template_document.id) incident_type.template_document = template_document if incident_type_in.commander_service: commander_service = service_service.get( db_session=db_session, service_id=incident_type_in.commander_service.id) incident_type.commander_service = commander_service if incident_type_in.liaison_service: liaison_service = service_service.get( db_session=db_session, service_id=incident_type_in.liaison_service.id) incident_type.liaison_service = liaison_service db_session.add(incident_type) db_session.commit() return incident_type
def get_suggested_documents(db_session, incident: Incident) -> list: """Get additional incident documents based on priority, type, and description.""" plugin = plugin_service.get_active_instance( db_session=db_session, project_id=incident.project.id, plugin_type="document-resolver" ) documents = [] if plugin: matches = plugin.instance.get(incident=incident, db_session=db_session) for m in matches: document = document_service.get(db_session=db_session, document_id=m.resource_state["id"]) documents.append(document) return documents
def create(*, db_session, incident_type_in: IncidentTypeCreate) -> IncidentType: if incident_type_in.template_document: template_document = document_service.get( db_session=db_session, document_id=incident_type_in.template_document.id) if incident_type_in.commander_service: commander_service = service_service.get( db_session=db_session, service_id=incident_type_in.commander_service.id) incident_type = IncidentType( **incident_type_in.dict( exclude={"commander_service", "template_document"}, ), commander_service=commander_service, template_document=template_document, ) db_session.add(incident_type) db_session.commit() return incident_type
def test_delete(session, document): from dispatch.document.service import delete, get delete(db_session=session, document_id=document.id) assert not get(db_session=session, document_id=document.id)
def test_get_document(session, document): from dispatch.document.service import get t_document = get(db_session=session, document_id=document.id) assert t_document.id == document.id