From e3b2b46bd968ba549d4fbaeac62246ad7a559529 Mon Sep 17 00:00:00 2001 From: Marc Vilanova <39573146+mvilanova@users.noreply.github.com> Date: Fri, 24 Jun 2022 09:46:48 -0700 Subject: [PATCH] Logs a warning if ticket plugin is not enabled on ticket creation (#2291) --- src/dispatch/incident/flows.py | 59 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/dispatch/incident/flows.py b/src/dispatch/incident/flows.py index 1c09dcfefc9d..246b6018414f 100644 --- a/src/dispatch/incident/flows.py +++ b/src/dispatch/incident/flows.py @@ -123,37 +123,40 @@ def create_incident_ticket(incident: Incident, db_session: SessionLocal): plugin = plugin_service.get_active_instance( db_session=db_session, project_id=incident.project.id, plugin_type="ticket" ) - if plugin: - title = incident.title - if incident.visibility == Visibility.restricted: - title = incident.incident_type.name + if not plugin: + log.warning("Incident ticket not created. No ticket plugin enabled.") + return - incident_type_plugin_metadata = incident_type_service.get_by_name_or_raise( - db_session=db_session, - project_id=incident.project.id, - incident_type_in=incident.incident_type, - ).get_meta(plugin.plugin.slug) - - ticket = plugin.instance.create( - incident.id, - title, - incident.incident_type.name, - incident.incident_priority.name, - incident.commander.individual.email, - incident.reporter.individual.email, - incident_type_plugin_metadata, - db_session=db_session, - ) - ticket.update({"resource_type": plugin.plugin.slug}) + title = incident.title + if incident.visibility == Visibility.restricted: + title = incident.incident_type.name - event_service.log( - db_session=db_session, - source=plugin.plugin.title, - description="Ticket created", - incident_id=incident.id, - ) + incident_type_plugin_metadata = incident_type_service.get_by_name_or_raise( + db_session=db_session, + project_id=incident.project.id, + incident_type_in=incident.incident_type, + ).get_meta(plugin.plugin.slug) + + ticket = plugin.instance.create( + incident.id, + title, + incident.incident_type.name, + incident.incident_priority.name, + incident.commander.individual.email, + incident.reporter.individual.email, + incident_type_plugin_metadata, + db_session=db_session, + ) + ticket.update({"resource_type": plugin.plugin.slug}) + + event_service.log( + db_session=db_session, + source=plugin.plugin.title, + description="Ticket created", + incident_id=incident.id, + ) - return ticket + return ticket def update_external_incident_ticket(