Passing ticket status flow logic to Ticket model

This commit is contained in:
Sam Splunks 2024-02-05 10:58:42 +01:00 committed by GitHub
parent 6498126b87
commit 8b53ef9505
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View File

@ -471,6 +471,7 @@ class Ticket(models.Model):
STATUS_CHOICES = helpdesk_settings.TICKET_STATUS_CHOICES
OPEN_STATUSES = helpdesk_settings.TICKET_OPEN_STATUSES
STATUS_CHOICES_FLOW = helpdesk_settings.TICKET_STATUS_CHOICES_FLOW
PRIORITY_CHOICES = helpdesk_settings.TICKET_PRIORITY_CHOICES
@ -710,6 +711,22 @@ class Ticket(models.Model):
return u'%s%s%s' % (self.get_status_display(), held_msg, dep_msg)
get_status = property(_get_status)
def _get_allowed_status_flow(self):
"""
Returns the list of allowed ticket status modifications for current state.
"""
status_id_list = self.STATUS_CHOICES_FLOW.get(self.status, ())
if status_id_list:
# keep defined statuses in order and add labels for display
status_dict = dict(helpdesk_settings.TICKET_STATUS_CHOICES)
new_statuses = [(status_id, status_dict.get(status_id, 1))
for status_id in status_id_list]
else:
# defaults to all choices if status was not mapped
new_statuses = helpdesk_settings.TICKET_STATUS_CHOICES
return new_statuses
get_allowed_status_flow = property(_get_allowed_status_flow)
def _get_ticket_url(self):
"""
Returns a publicly-viewable URL for this ticket, used when giving

View File

@ -121,11 +121,24 @@ TICKET_STATUS_CHOICES = getattr(settings,
'HELPDESK_TICKET_STATUS_CHOICES',
DEFAULT_TICKET_STATUS_CHOICES)
# List of status choices considered as "open"
DEFAULT_TICKET_OPEN_STATUSES = (OPEN_STATUS, REOPENED_STATUS)
TICKET_OPEN_STATUSES = getattr(settings,
'HELPDESK_TICKET_OPEN_STATUSES',
DEFAULT_TICKET_OPEN_STATUSES)
# New status list choices depending on current ticket status
DEFAULT_TICKET_STATUS_CHOICES_FLOW = {
OPEN_STATUS: (OPEN_STATUS, RESOLVED_STATUS, CLOSED_STATUS, DUPLICATE_STATUS,),
REOPENED_STATUS: (REOPENED_STATUS, RESOLVED_STATUS, CLOSED_STATUS, DUPLICATE_STATUS,),
RESOLVED_STATUS: (REOPENED_STATUS, RESOLVED_STATUS, CLOSED_STATUS,),
CLOSED_STATUS: (REOPENED_STATUS, CLOSED_STATUS,),
DUPLICATE_STATUS: (REOPENED_STATUS, DUPLICATE_STATUS,),
}
TICKET_STATUS_CHOICES_FLOW = getattr(settings,
'HELPDESK_TICKET_STATUS_CHOICES_FLOW',
DEFAULT_TICKET_STATUS_CHOICES_FLOW)
# Ticket priority choices
DEFAULT_TICKET_PRIORITY_CHOICES = (
(1, _('1. Critical')),