From 8b53ef9505e761e17cda15d7d8111a2501072d90 Mon Sep 17 00:00:00 2001 From: Sam Splunks <72095718+samsplunks@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:58:42 +0100 Subject: [PATCH] Passing ticket status flow logic to Ticket model --- helpdesk/models.py | 17 +++++++++++++++++ helpdesk/settings.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/helpdesk/models.py b/helpdesk/models.py index 385281db..620cb54d 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -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 diff --git a/helpdesk/settings.py b/helpdesk/settings.py index fbbc8bad..cf5ca644 100644 --- a/helpdesk/settings.py +++ b/helpdesk/settings.py @@ -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')),