Skip to content

Commit

Permalink
Enable local_mode on actions
Browse files Browse the repository at this point in the history
  • Loading branch information
santteegt committed Jun 5, 2020
1 parent 1525683 commit 73ef595
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
27 changes: 15 additions & 12 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger = logging.getLogger(__name__)

glpi_api_uri, glpi_app_token, glpi_auth_token, local_mode = load_glpi_config()
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token)
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token) if not local_mode else None


class ComputeResourceForm(FormAction):
Expand Down Expand Up @@ -253,19 +253,22 @@ def submit(
]

if tracker.get_slot(EntitySlotEnum.CONFIRM):
# priorities = GLPIService.priority_values()
# priority_values = list(priorities.keys())
# glpi_priority = priorities[priority_values[1]] # media
ticket: Ticket = Ticket({
'username': 'normal', # TODO: set the actual logged in user
'title': 'Peticion de Maquina Virtual',
'description': remove_accents(request_description),
# 'priority': glpi_priority
'itilcategories_id': 54 # Equipos de computo
})
if local_mode:
ticket_id: Text = "{:04d}".format(random.randint(1, 1000))
dispatcher.utter_message(f"This action would create a ticket with params: {ticket}")
# ticket_id: Text = "{:04d}".format(random.randint(1, 1000))
ticket_id: Text = "DUMMY"
events.append(SlotSet(EntitySlotEnum.TICKET_NO, ticket_id))
else: # TODO: integrate with GLPI
# priorities = GLPIService.priority_values()
# priority_values = list(priorities.keys())
# glpi_priority = priorities[priority_values[1]] # media
ticket: Ticket = Ticket({
'username': 'normal', # TODO: set the actual logged in user
'title': 'Peticion de Maquina Virtual',
'description': remove_accents(request_description),
# 'priority': glpi_priority
'itilcategories_id': 54 # Equipos de computo
})
try:
response = glpi.create_ticket(ticket, ticket_type=2) # Solicitud
ticket_id = response['id']
Expand Down
38 changes: 19 additions & 19 deletions actions/actions_helpdesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger = logging.getLogger(__name__)

glpi_api_uri, glpi_app_token, glpi_auth_token, local_mode = load_glpi_config()
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token)
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token) if not local_mode else None


class OpenIncidentForm(FormAction):
Expand Down Expand Up @@ -155,29 +155,29 @@ def submit(
SlotSet(EntitySlotEnum.CONFIRM, None)]

if tracker.get_slot(EntitySlotEnum.CONFIRM):
# Check priority and set number value accordingly
# priorities = GLPIService.priority_values()
# priority_values = list(priorities.keys())
# if priority in priority_values:
# glpi_priority = priorities[priority]
# else:
# logger.warning(f'Priority value not found: {priority}. Setting it to default: (media)')
# glpi_priority = priorities[priority_values[1]]

ticket: Ticket = Ticket({
'username': 'normal', # TODO: set the actual logged in user
'title': incident_title,
'description': remove_accents(incident_description),
# 'priority': glpi_priority
'itilcategories_id': int(itilcategory_id),
'alternative_email': email # TODO: set as conditional if username is not logged in
})

if local_mode:
dispatcher.utter_message(f"This action would create a ticket with params: {ticket}")
ticket_id = "DUMMY"
events.append(SlotSet(EntitySlotEnum.TICKET_NO, ticket_id))
else: # TODO: integrate with GLPI
# Check priority and set number value accordingly
# priorities = GLPIService.priority_values()
# priority_values = list(priorities.keys())
# if priority in priority_values:
# glpi_priority = priorities[priority]
# else:
# logger.warning(f'Priority value not found: {priority}. Setting it to default: (media)')
# glpi_priority = priorities[priority_values[1]]

ticket: Ticket = Ticket({
'username': 'normal', # TODO: set the actual logged in user
'title': incident_title,
'description': remove_accents(incident_description),
# 'priority': glpi_priority
'itilcategories_id': int(itilcategory_id),
'alternative_email': email # TODO: set as conditional if username is not logged in
})
# logger.info(f'Ticket to be created: {ticket}')
try:
response = glpi.create_ticket(ticket)
ticket_id = response['id']
Expand Down
27 changes: 16 additions & 11 deletions actions/actions_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logger = logging.getLogger(__name__)

glpi_api_uri, glpi_app_token, glpi_auth_token, local_mode = load_glpi_config()
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token)
glpi = GLPIService.get_instance(glpi_api_uri, glpi_app_token, glpi_auth_token) if not local_mode else None


class BiometricsReportForm(FormAction):
Expand Down Expand Up @@ -152,21 +152,26 @@ def submit(
'itilcategories_id': 60 # Reporte de datos
})

try:
response = glpi.create_ticket(ticket, ticket_type=2) # Solicitud
ticket_id = response['id']
# This is not actually required as its value is sent directly to the utter_message
if local_mode:
dispatcher.utter_message(f"This action would create a ticket with params: {ticket}")
ticket_id = 'DUMMY'
events.append(SlotSet(EntitySlotEnum.TICKET_NO, ticket_id))
except GlpiException as e:
logger.error("Error when trying to create a ticket", e)
logger.error(f"Ticket: {ticket}")
dispatcher.utter_message(template=UtteranceEnum.PROCESS_FAILED)
return events
else:
try:
response = glpi.create_ticket(ticket, ticket_type=2) # Solicitud
ticket_id = response['id']
# This is not actually required as its value is sent directly to the utter_message
events.append(SlotSet(EntitySlotEnum.TICKET_NO, ticket_id))
except GlpiException as e:
logger.error("Error when trying to create a ticket", e)
logger.error(f"Ticket: {ticket}")
dispatcher.utter_message(template=UtteranceEnum.PROCESS_FAILED)
return events
dispatcher.utter_message(template=UtteranceEnum.TICKET_NO, ticket_no=ticket_id)
dispatcher.utter_message(template=UtteranceEnum.CONFIRM_REQUEST)
# dispatcher.utter_message(
# "This action will create a ticket for requesting a biometrics report with "
# + f"ID: {personal_id} BIO_ID: {biometrics_id}"
# )
# return [AllSlotsReset()]
return events
return events

0 comments on commit 73ef595

Please sign in to comment.