2008-02-06 05:36:07 +01:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
2008-02-06 05:36:07 +01:00
|
|
|
|
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-06 05:36:07 +01:00
|
|
|
models.py - Model (and hence database) definitions. This is the core of the
|
|
|
|
helpdesk structure.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
2008-02-06 05:36:07 +01:00
|
|
|
|
2015-12-16 16:09:15 +01:00
|
|
|
from django.contrib.auth.models import Permission
|
2018-08-20 01:08:45 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
2015-12-16 16:09:15 +01:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2020-10-31 18:24:22 +01:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
2008-01-15 01:20:00 +01:00
|
|
|
from django.db import models
|
|
|
|
from django.conf import settings
|
2016-11-21 03:12:19 +01:00
|
|
|
from django.utils import timezone
|
2009-10-13 12:28:42 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _, ugettext
|
2018-12-28 09:13:52 +01:00
|
|
|
from io import StringIO
|
2018-06-27 08:10:20 +02:00
|
|
|
import re
|
2019-03-07 21:58:04 +01:00
|
|
|
import os
|
|
|
|
import mimetypes
|
2019-02-06 14:24:43 +01:00
|
|
|
import datetime
|
2013-01-23 01:35:18 +01:00
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
from markdown import markdown
|
|
|
|
from markdown.extensions import Extension
|
|
|
|
|
2020-01-27 17:37:59 +01:00
|
|
|
import pinax.teams.models
|
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
|
2018-09-08 20:36:35 +02:00
|
|
|
import uuid
|
2015-11-18 15:26:08 +01:00
|
|
|
|
2019-10-11 15:50:35 +02:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
from .templated_email import send_templated_mail
|
|
|
|
|
2018-07-19 06:06:57 +02:00
|
|
|
|
2019-06-16 10:25:29 +02:00
|
|
|
def format_time_spent(time_spent):
|
|
|
|
if time_spent:
|
2019-12-25 09:21:47 +01:00
|
|
|
time_spent = "{0:02d}h:{1:02d}m".format(
|
|
|
|
time_spent.seconds // 3600,
|
|
|
|
time_spent.seconds // 60
|
2019-06-16 10:25:29 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
time_spent = ""
|
|
|
|
return time_spent
|
|
|
|
|
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
class EscapeHtml(Extension):
|
|
|
|
def extendMarkdown(self, md, md_globals):
|
|
|
|
del md.preprocessors['html_block']
|
|
|
|
del md.inlinePatterns['html']
|
|
|
|
|
|
|
|
|
|
|
|
def get_markdown(text):
|
|
|
|
if not text:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
return mark_safe(
|
|
|
|
markdown(
|
|
|
|
text,
|
|
|
|
extensions=[
|
|
|
|
EscapeHtml(), 'markdown.extensions.nl2br',
|
|
|
|
'markdown.extensions.fenced_code'
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Queue(models.Model):
|
2007-12-27 02:35:34 +01:00
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
A queue is a collection of tickets into what would generally be business
|
2007-12-27 02:35:34 +01:00
|
|
|
areas or departments.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
For example, a company may have a queue for each Product they provide, or
|
2007-12-27 02:35:34 +01:00
|
|
|
a queue for each of Accounts, Pre-Sales, and Support.
|
|
|
|
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Slug'),
|
2015-12-16 16:08:46 +01:00
|
|
|
max_length=50,
|
2015-12-18 14:56:53 +01:00
|
|
|
unique=True,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('This slug is used when building ticket ID\'s. Once set, '
|
2016-10-21 17:14:12 +02:00
|
|
|
'try not to change it or e-mailing may get messy.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_address = models.EmailField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('All outgoing e-mails for this queue will use this e-mail '
|
2016-10-21 17:14:12 +02:00
|
|
|
'address. If you use IMAP or POP3, this should be the e-mail '
|
|
|
|
'address for that mailbox.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-11-18 02:43:50 +01:00
|
|
|
|
|
|
|
locale = models.CharField(
|
|
|
|
_('Locale'),
|
|
|
|
max_length=10,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Locale of this queue. All correspondence in this '
|
|
|
|
'queue will be in this language.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
allow_public_submission = models.BooleanField(
|
|
|
|
_('Allow Public Submission?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Should this queue be listed on the public submission form?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
allow_email_submission = models.BooleanField(
|
|
|
|
_('Allow E-Mail Submission?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('Do you want to poll the e-mail box below for new '
|
2016-10-21 17:14:12 +02:00
|
|
|
'tickets?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
escalate_days = models.IntegerField(
|
|
|
|
_('Escalation Days'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('For tickets which are not held, how often do you wish to '
|
2016-10-21 17:14:12 +02:00
|
|
|
'increase their priority? Set to 0 for no escalation.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-03-05 04:29:01 +01:00
|
|
|
new_ticket_cc = models.CharField(
|
2008-08-19 10:50:38 +02:00
|
|
|
_('New Ticket CC Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2011-03-05 04:29:01 +01:00
|
|
|
max_length=200,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('If an e-mail address is entered here, then it will '
|
2016-10-21 17:14:12 +02:00
|
|
|
'receive notification of all new tickets created for this queue. '
|
|
|
|
'Enter a comma between multiple e-mail addresses.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-03-05 04:29:01 +01:00
|
|
|
updated_ticket_cc = models.CharField(
|
2008-08-19 10:50:38 +02:00
|
|
|
_('Updated Ticket CC Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2011-03-05 04:29:01 +01:00
|
|
|
max_length=200,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('If an e-mail address is entered here, then it will '
|
2016-10-21 17:14:12 +02:00
|
|
|
'receive notification of all activity (new tickets, closed '
|
|
|
|
'tickets, updates, reassignments, etc) for this queue. Separate '
|
|
|
|
'multiple addresses with a comma.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-03-01 20:49:34 +01:00
|
|
|
enable_notifications_on_email_events = models.BooleanField(
|
|
|
|
_('Notify contacts when email updates arrive'),
|
|
|
|
blank=True,
|
|
|
|
default=False,
|
|
|
|
help_text=_('When an email arrives to either create a ticket or to '
|
2018-12-28 17:32:49 +01:00
|
|
|
'interact with an existing discussion. Should email notifications be sent ? '
|
|
|
|
'Note: the new_ticket_cc and updated_ticket_cc work independently of this feature'),
|
|
|
|
)
|
2016-03-01 20:49:34 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
email_box_type = models.CharField(
|
|
|
|
_('E-Mail Box Type'),
|
|
|
|
max_length=5,
|
2016-10-29 10:08:57 +02:00
|
|
|
choices=(('pop3', _('POP 3')), ('imap', _('IMAP')), ('local', _('Local Directory'))),
|
2008-08-19 10:50:38 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('E-Mail server type for creating tickets automatically '
|
2016-10-29 08:33:29 +02:00
|
|
|
'from a mailbox - both POP3 and IMAP are supported, as well as '
|
|
|
|
'reading from a local directory.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_box_host = models.CharField(
|
|
|
|
_('E-Mail Hostname'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Your e-mail server address - either the domain name or '
|
2016-10-21 17:14:12 +02:00
|
|
|
'IP address. May be "localhost".'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_box_port = models.IntegerField(
|
|
|
|
_('E-Mail Port'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Port number to use for accessing e-mail. Default for '
|
2016-10-21 17:14:12 +02:00
|
|
|
'POP3 is "110", and for IMAP is "143". This may differ on some '
|
|
|
|
'servers. Leave it blank to use the defaults.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-08-20 03:57:41 +02:00
|
|
|
email_box_ssl = models.BooleanField(
|
|
|
|
_('Use SSL for E-Mail?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-20 03:57:41 +02:00
|
|
|
help_text=_('Whether to use SSL for IMAP or POP3 - the default ports '
|
2016-10-21 17:14:12 +02:00
|
|
|
'when using SSL are 993 for IMAP and 995 for POP3.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
email_box_user = models.CharField(
|
|
|
|
_('E-Mail Username'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Username for accessing this mailbox.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_box_pass = models.CharField(
|
|
|
|
_('E-Mail Password'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Password for the above username'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_box_imap_folder = models.CharField(
|
|
|
|
_('IMAP Folder'),
|
|
|
|
max_length=100,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If using IMAP, what folder do you wish to fetch messages '
|
2016-10-21 17:14:12 +02:00
|
|
|
'from? This allows you to use one IMAP account for multiple '
|
|
|
|
'queues, by filtering messages on your IMAP server into separate '
|
|
|
|
'folders. Default: INBOX.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-09-15 02:35:18 +02:00
|
|
|
email_box_local_dir = models.CharField(
|
|
|
|
_('E-Mail Local Directory'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If using a local directory, what directory path do you '
|
2016-10-29 10:08:57 +02:00
|
|
|
'wish to poll for new email? '
|
|
|
|
'Example: /var/lib/mail/helpdesk/'),
|
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2015-12-16 16:08:46 +01:00
|
|
|
permission_name = models.CharField(
|
|
|
|
_('Django auth permission name'),
|
2017-02-12 11:33:53 +01:00
|
|
|
max_length=72, # based on prepare_permission_name() pre-pending chars to slug
|
2015-12-16 16:08:46 +01:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
2015-12-18 14:56:53 +01:00
|
|
|
editable=False,
|
2015-12-16 16:08:46 +01:00
|
|
|
help_text=_('Name used in the django.contrib.auth permission system'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2015-12-16 16:08:46 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
email_box_interval = models.IntegerField(
|
|
|
|
_('E-Mail Check Interval'),
|
|
|
|
help_text=_('How often do you wish to check this mailbox? (in Minutes)'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
default='5',
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
email_box_last_check = models.DateTimeField(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
editable=False,
|
|
|
|
# This is updated by management/commands/get_mail.py.
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-12-10 22:37:34 +01:00
|
|
|
socks_proxy_type = models.CharField(
|
|
|
|
_('Socks Proxy Type'),
|
|
|
|
max_length=8,
|
|
|
|
choices=(('socks4', _('SOCKS4')), ('socks5', _('SOCKS5'))),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('SOCKS4 or SOCKS5 allows you to proxy your connections through a SOCKS server.'),
|
|
|
|
)
|
|
|
|
|
|
|
|
socks_proxy_host = models.GenericIPAddressField(
|
|
|
|
_('Socks Proxy Host'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2014-12-11 00:42:20 +01:00
|
|
|
help_text=_('Socks proxy IP address. Default: 127.0.0.1'),
|
2014-12-10 22:37:34 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
socks_proxy_port = models.IntegerField(
|
|
|
|
_('Socks Proxy Port'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2014-12-11 00:42:20 +01:00
|
|
|
help_text=_('Socks proxy port number. Default: 9150 (default TOR port)'),
|
2014-12-10 22:37:34 +01:00
|
|
|
)
|
|
|
|
|
2016-09-15 02:35:18 +02:00
|
|
|
logging_type = models.CharField(
|
|
|
|
_('Logging Type'),
|
2016-10-29 10:20:16 +02:00
|
|
|
max_length=5,
|
|
|
|
choices=(
|
2016-10-29 10:08:57 +02:00
|
|
|
('none', _('None')),
|
|
|
|
('debug', _('Debug')),
|
|
|
|
('info', _('Information')),
|
|
|
|
('warn', _('Warning')),
|
|
|
|
('error', _('Error')),
|
|
|
|
('crit', _('Critical'))
|
|
|
|
),
|
2016-09-15 02:35:18 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Set the default logging level. All messages at that '
|
2016-10-29 10:08:57 +02:00
|
|
|
'level or above will be logged to the directory set '
|
|
|
|
'below. If no level is set, logging will be disabled.'),
|
|
|
|
)
|
2016-09-15 02:35:18 +02:00
|
|
|
|
|
|
|
logging_dir = models.CharField(
|
|
|
|
_('Logging Directory'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If logging is enabled, what directory should we use to '
|
2016-10-29 10:08:57 +02:00
|
|
|
'store log files for this queue? '
|
2020-11-25 10:20:36 +01:00
|
|
|
'The standard logging mechanims are used if no directory is set'),
|
2016-10-29 10:08:57 +02:00
|
|
|
)
|
2016-09-15 02:35:18 +02:00
|
|
|
|
2016-02-17 09:40:08 +01:00
|
|
|
default_owner = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.SET_NULL,
|
2016-02-17 09:40:08 +01:00
|
|
|
related_name='default_owner',
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
verbose_name=_('Default owner'),
|
|
|
|
)
|
|
|
|
|
2019-02-19 23:01:51 +01:00
|
|
|
dedicated_time = models.DurationField(
|
|
|
|
help_text=_("Time to be spent on this Queue in total"),
|
|
|
|
blank=True, null=True
|
|
|
|
)
|
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return "%s" % self.title
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('title',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Queue')
|
|
|
|
verbose_name_plural = _('Queues')
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-01-07 21:22:13 +01:00
|
|
|
def _from_address(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Short property to provide a sender address in SMTP format,
|
|
|
|
eg 'Name <email>'. We do this so we can put a simple error message
|
|
|
|
in the sender name field, so hopefully the admin can see and fix it.
|
|
|
|
"""
|
2008-01-15 01:20:00 +01:00
|
|
|
if not self.email_address:
|
2018-06-27 08:10:20 +02:00
|
|
|
# must check if given in format "Foo <foo@example.com>"
|
|
|
|
default_email = re.match(".*<(?P<email>.*@*.)>", settings.DEFAULT_FROM_EMAIL)
|
|
|
|
if default_email is not None:
|
|
|
|
# already in the right format, so just include it here
|
|
|
|
return u'NO QUEUE EMAIL ADDRESS DEFINED %s' % settings.DEFAULT_FROM_EMAIL
|
|
|
|
else:
|
|
|
|
return u'NO QUEUE EMAIL ADDRESS DEFINED <%s>' % settings.DEFAULT_FROM_EMAIL
|
2008-01-15 01:20:00 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
return u'%s <%s>' % (self.title, self.email_address)
|
2008-01-07 21:22:13 +01:00
|
|
|
from_address = property(_from_address)
|
|
|
|
|
2019-02-06 14:24:43 +01:00
|
|
|
@property
|
|
|
|
def time_spent(self):
|
|
|
|
"""Return back total time spent on the ticket. This is calculated value
|
|
|
|
based on total sum from all FollowUps
|
|
|
|
"""
|
|
|
|
total = datetime.timedelta(0)
|
|
|
|
for val in self.ticket_set.all():
|
|
|
|
if val.time_spent:
|
|
|
|
total = total + val.time_spent
|
|
|
|
return total
|
|
|
|
|
2019-06-16 10:25:29 +02:00
|
|
|
@property
|
|
|
|
def time_spent_formated(self):
|
|
|
|
return format_time_spent(self.time_spent)
|
|
|
|
|
2015-12-16 17:05:25 +01:00
|
|
|
def prepare_permission_name(self):
|
|
|
|
"""Prepare internally the codename for the permission and store it in permission_name.
|
|
|
|
:return: The codename that can be used to create a new Permission object.
|
|
|
|
"""
|
|
|
|
# Prepare the permission associated to this Queue
|
|
|
|
basename = "queue_access_%s" % self.slug
|
|
|
|
self.permission_name = "helpdesk.%s" % basename
|
|
|
|
return basename
|
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
def save(self, *args, **kwargs):
|
2008-01-07 21:22:13 +01:00
|
|
|
if self.email_box_type == 'imap' and not self.email_box_imap_folder:
|
|
|
|
self.email_box_imap_folder = 'INBOX'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-12-11 00:42:20 +01:00
|
|
|
if self.socks_proxy_type:
|
|
|
|
if not self.socks_proxy_host:
|
|
|
|
self.socks_proxy_host = '127.0.0.1'
|
|
|
|
if not self.socks_proxy_port:
|
|
|
|
self.socks_proxy_port = 9150
|
2014-12-11 11:03:36 +01:00
|
|
|
else:
|
|
|
|
self.socks_proxy_host = None
|
|
|
|
self.socks_proxy_port = None
|
2014-12-11 00:42:20 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
if not self.email_box_port:
|
2008-08-20 03:57:41 +02:00
|
|
|
if self.email_box_type == 'imap' and self.email_box_ssl:
|
|
|
|
self.email_box_port = 993
|
|
|
|
elif self.email_box_type == 'imap' and not self.email_box_ssl:
|
2008-08-19 10:50:38 +02:00
|
|
|
self.email_box_port = 143
|
2008-08-20 03:57:41 +02:00
|
|
|
elif self.email_box_type == 'pop3' and self.email_box_ssl:
|
|
|
|
self.email_box_port = 995
|
|
|
|
elif self.email_box_type == 'pop3' and not self.email_box_ssl:
|
2008-08-19 10:50:38 +02:00
|
|
|
self.email_box_port = 110
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2015-12-16 17:05:25 +01:00
|
|
|
if not self.id:
|
2015-12-18 14:35:50 +01:00
|
|
|
# Prepare the permission codename and the permission
|
|
|
|
# (even if they are not needed with the current configuration)
|
2015-12-16 17:05:25 +01:00
|
|
|
basename = self.prepare_permission_name()
|
|
|
|
|
2015-12-18 14:35:50 +01:00
|
|
|
Permission.objects.create(
|
|
|
|
name=_("Permission for queue: ") + self.title,
|
2017-01-13 11:52:29 +01:00
|
|
|
content_type=ContentType.objects.get_for_model(self.__class__),
|
2015-12-18 14:35:50 +01:00
|
|
|
codename=basename,
|
|
|
|
)
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
super(Queue, self).save(*args, **kwargs)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2015-12-16 17:15:54 +01:00
|
|
|
def delete(self, *args, **kwargs):
|
|
|
|
permission_name = self.permission_name
|
|
|
|
super(Queue, self).delete(*args, **kwargs)
|
|
|
|
|
|
|
|
# once the Queue is safely deleted, remove the permission (if exists)
|
|
|
|
if permission_name:
|
|
|
|
try:
|
|
|
|
p = Permission.objects.get(codename=permission_name[9:])
|
|
|
|
p.delete()
|
|
|
|
except ObjectDoesNotExist:
|
|
|
|
pass
|
|
|
|
|
2008-01-15 01:20:00 +01:00
|
|
|
|
2018-09-08 20:36:35 +02:00
|
|
|
def mk_secret():
|
|
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Ticket(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
To allow a ticket to be entered as quickly as possible, only the
|
|
|
|
bare minimum fields are required. These basically allow us to
|
|
|
|
sort and manage the ticket. The user can always go back and
|
2007-12-27 01:29:17 +01:00
|
|
|
enter more information later.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
A good example of this is when a customer is on the phone, and
|
2007-12-27 01:29:17 +01:00
|
|
|
you want to give them a ticket ID as quickly as possible. You can
|
2008-08-19 10:50:38 +02:00
|
|
|
enter some basic info, save the ticket, give the customer the ID
|
2007-12-27 01:29:17 +01:00
|
|
|
and get off the phone, then add in further detail at a later time
|
|
|
|
(once the customer is not on the line).
|
2007-12-27 02:35:34 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
Note that assigned_to is optional - unassigned tickets are displayed on
|
2007-12-27 02:35:34 +01:00
|
|
|
the dashboard to prompt users to take ownership of them.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
OPEN_STATUS = 1
|
|
|
|
REOPENED_STATUS = 2
|
|
|
|
RESOLVED_STATUS = 3
|
|
|
|
CLOSED_STATUS = 4
|
2011-02-03 12:42:51 +01:00
|
|
|
DUPLICATE_STATUS = 5
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
STATUS_CHOICES = (
|
2008-05-07 11:04:18 +02:00
|
|
|
(OPEN_STATUS, _('Open')),
|
|
|
|
(REOPENED_STATUS, _('Reopened')),
|
|
|
|
(RESOLVED_STATUS, _('Resolved')),
|
|
|
|
(CLOSED_STATUS, _('Closed')),
|
2014-07-30 10:41:10 +02:00
|
|
|
(DUPLICATE_STATUS, _('Duplicate')),
|
2007-12-27 01:29:17 +01:00
|
|
|
)
|
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
PRIORITY_CHOICES = (
|
2008-05-07 11:04:18 +02:00
|
|
|
(1, _('1. Critical')),
|
|
|
|
(2, _('2. High')),
|
|
|
|
(3, _('3. Normal')),
|
|
|
|
(4, _('4. Low')),
|
|
|
|
(5, _('5. Very Low')),
|
2008-01-10 01:28:45 +01:00
|
|
|
)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=200,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-16 05:52:30 +01:00
|
|
|
|
2011-01-29 07:10:12 +01:00
|
|
|
queue = models.ForeignKey(
|
|
|
|
Queue,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Queue'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
created = models.DateTimeField(
|
|
|
|
_('Created'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Date this ticket was first created'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
modified = models.DateTimeField(
|
|
|
|
_('Modified'),
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Date this ticket was most recently changed.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
submitter_email = models.EmailField(
|
|
|
|
_('Submitter E-Mail'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('The submitter will receive an email for all public '
|
2016-10-21 17:14:12 +02:00
|
|
|
'follow-ups left for this task.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
assigned_to = models.ForeignKey(
|
2014-09-10 01:06:50 +02:00
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2008-08-19 10:50:38 +02:00
|
|
|
related_name='assigned_to',
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Assigned to'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
status = models.IntegerField(
|
|
|
|
_('Status'),
|
|
|
|
choices=STATUS_CHOICES,
|
|
|
|
default=OPEN_STATUS,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
on_hold = models.BooleanField(
|
|
|
|
_('On Hold'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('If a ticket is on hold, it will not automatically be escalated.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
_('Description'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('The content of the customers query.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
resolution = models.TextField(
|
|
|
|
_('Resolution'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('The resolution provided to the customer by our staff.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
priority = models.IntegerField(
|
|
|
|
_('Priority'),
|
|
|
|
choices=PRIORITY_CHOICES,
|
|
|
|
default=3,
|
|
|
|
blank=3,
|
|
|
|
help_text=_('1 = Highest Priority, 5 = Low Priority'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2012-01-20 21:48:38 +01:00
|
|
|
due_date = models.DateTimeField(
|
|
|
|
_('Due on'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
last_escalation = models.DateTimeField(
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
editable=False,
|
|
|
|
help_text=_('The date this ticket was last escalated - updated '
|
2016-10-21 17:14:12 +02:00
|
|
|
'automatically by management/commands/escalate_tickets.py.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-10 01:28:45 +01:00
|
|
|
|
2018-09-08 20:36:35 +02:00
|
|
|
secret_key = models.CharField(
|
|
|
|
_("Secret key needed for viewing/editing ticket by non-logged in users"),
|
|
|
|
max_length=36,
|
|
|
|
default=mk_secret,
|
|
|
|
)
|
|
|
|
|
2020-01-07 13:33:06 +01:00
|
|
|
kbitem = models.ForeignKey(
|
|
|
|
"KBItem",
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_('Knowledge base item the user was viewing when they created this ticket.'),
|
|
|
|
)
|
|
|
|
|
2020-10-29 23:29:16 +01:00
|
|
|
merged_to = models.ForeignKey(
|
|
|
|
'self',
|
|
|
|
verbose_name=_('merged to'),
|
|
|
|
related_name='merged_tickets',
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
null=True,
|
|
|
|
blank=True
|
|
|
|
)
|
|
|
|
|
2019-02-06 14:24:43 +01:00
|
|
|
@property
|
|
|
|
def time_spent(self):
|
|
|
|
"""Return back total time spent on the ticket. This is calculated value
|
|
|
|
based on total sum from all FollowUps
|
|
|
|
"""
|
|
|
|
total = datetime.timedelta(0)
|
|
|
|
for val in self.followup_set.all():
|
|
|
|
if val.time_spent:
|
|
|
|
total = total + val.time_spent
|
|
|
|
return total
|
|
|
|
|
2019-06-16 10:25:29 +02:00
|
|
|
@property
|
|
|
|
def time_spent_formated(self):
|
|
|
|
return format_time_spent(self.time_spent)
|
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
def send(self, roles, dont_send_to=None, **kwargs):
|
|
|
|
"""
|
|
|
|
Send notifications to everyone interested in this ticket.
|
|
|
|
|
|
|
|
The the roles argument is a dictionary mapping from roles to (template, context) pairs.
|
2018-12-28 16:53:28 +01:00
|
|
|
If a role is not present in the dictionary, users of that type will not receive the notification.
|
2018-10-31 16:24:57 +01:00
|
|
|
|
|
|
|
The following roles exist:
|
|
|
|
|
|
|
|
- 'submitter'
|
|
|
|
- 'new_ticket_cc'
|
|
|
|
- 'ticket_cc'
|
|
|
|
- 'assigned_to'
|
|
|
|
|
|
|
|
Here is an example roles dictionary:
|
|
|
|
|
|
|
|
{
|
|
|
|
'submitter': (template_name, context),
|
|
|
|
'assigned_to': (template_name2, context),
|
|
|
|
}
|
|
|
|
|
|
|
|
**kwargs are passed to send_templated_mail defined in templated_mail.py
|
|
|
|
|
|
|
|
returns the set of email addresses the notification was delivered to.
|
|
|
|
|
|
|
|
"""
|
|
|
|
recipients = set()
|
|
|
|
|
|
|
|
if dont_send_to is not None:
|
|
|
|
recipients.update(dont_send_to)
|
|
|
|
|
2020-01-17 18:11:52 +01:00
|
|
|
recipients.add(self.queue.email_address)
|
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
def should_receive(email):
|
|
|
|
return email and email not in recipients
|
|
|
|
|
|
|
|
def send(role, recipient):
|
|
|
|
if recipient and recipient not in recipients and role in roles:
|
|
|
|
template, context = roles[role]
|
|
|
|
send_templated_mail(template, context, recipient, sender=self.queue.from_address, **kwargs)
|
|
|
|
recipients.add(recipient)
|
|
|
|
send('submitter', self.submitter_email)
|
2018-12-28 16:53:28 +01:00
|
|
|
send('ticket_cc', self.queue.updated_ticket_cc)
|
2018-10-31 16:24:57 +01:00
|
|
|
send('new_ticket_cc', self.queue.new_ticket_cc)
|
2018-11-01 19:30:34 +01:00
|
|
|
if self.assigned_to:
|
2018-10-31 16:24:57 +01:00
|
|
|
send('assigned_to', self.assigned_to.email)
|
2018-12-28 16:53:28 +01:00
|
|
|
if self.queue.enable_notifications_on_email_events:
|
|
|
|
for cc in self.ticketcc_set.all():
|
|
|
|
send('ticket_cc', cc.email_address)
|
2018-10-31 16:24:57 +01:00
|
|
|
return recipients
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
def _get_assigned_to(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" Custom property to allow us to easily print 'Unassigned' if a
|
|
|
|
ticket has no owner, or the users name if it's assigned. If the user
|
2007-12-27 02:35:34 +01:00
|
|
|
has a full name configured, we use that, otherwise their username. """
|
2007-12-27 01:29:17 +01:00
|
|
|
if not self.assigned_to:
|
2008-05-07 11:04:18 +02:00
|
|
|
return _('Unassigned')
|
2007-12-27 01:29:17 +01:00
|
|
|
else:
|
|
|
|
if self.assigned_to.get_full_name():
|
|
|
|
return self.assigned_to.get_full_name()
|
|
|
|
else:
|
2014-10-22 07:18:04 +02:00
|
|
|
return self.assigned_to.get_username()
|
2007-12-27 01:29:17 +01:00
|
|
|
get_assigned_to = property(_get_assigned_to)
|
|
|
|
|
2008-01-07 21:22:13 +01:00
|
|
|
def _get_ticket(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" A user-friendly ticket ID, which is a combination of ticket ID
|
|
|
|
and queue slug. This is generally used in e-mail subjects. """
|
2008-01-07 21:22:13 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return u"[%s]" % self.ticket_for_url
|
2008-01-07 21:22:13 +01:00
|
|
|
ticket = property(_get_ticket)
|
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def _get_ticket_for_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
""" A URL-friendly ticket ID, used in links. """
|
2008-05-07 11:04:18 +02:00
|
|
|
return u"%s-%s" % (self.queue.slug, self.id)
|
2008-01-16 01:26:24 +01:00
|
|
|
ticket_for_url = property(_get_ticket_for_url)
|
|
|
|
|
2014-09-19 16:01:15 +02:00
|
|
|
def _get_priority_css_class(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
2014-09-19 16:01:15 +02:00
|
|
|
Return the boostrap class corresponding to the priority.
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
2014-09-22 10:01:08 +02:00
|
|
|
if self.priority == 2:
|
2014-09-19 16:01:15 +02:00
|
|
|
return "warning"
|
2014-09-22 10:01:08 +02:00
|
|
|
elif self.priority == 1:
|
2014-09-19 16:01:15 +02:00
|
|
|
return "danger"
|
2016-09-09 10:03:32 +02:00
|
|
|
elif self.priority == 5:
|
|
|
|
return "success"
|
2014-09-19 16:01:15 +02:00
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
get_priority_css_class = property(_get_priority_css_class)
|
2008-08-12 01:24:18 +02:00
|
|
|
|
2008-01-16 05:52:30 +01:00
|
|
|
def _get_status(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Displays the ticket status, with an "On Hold" message if needed.
|
|
|
|
"""
|
2008-01-16 05:52:30 +01:00
|
|
|
held_msg = ''
|
2016-10-23 22:09:17 +02:00
|
|
|
if self.on_hold:
|
|
|
|
held_msg = _(' - On Hold')
|
2013-03-06 11:19:13 +01:00
|
|
|
dep_msg = ''
|
2016-10-21 17:14:12 +02:00
|
|
|
if not self.can_be_resolved:
|
|
|
|
dep_msg = _(' - Open dependencies')
|
2013-03-06 11:19:13 +01:00
|
|
|
return u'%s%s%s' % (self.get_status_display(), held_msg, dep_msg)
|
2008-01-16 05:52:30 +01:00
|
|
|
get_status = property(_get_status)
|
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def _get_ticket_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Returns a publicly-viewable URL for this ticket, used when giving
|
|
|
|
a URL to the submitter of a ticket.
|
|
|
|
"""
|
2008-01-16 01:26:24 +01:00
|
|
|
from django.contrib.sites.models import Site
|
2017-12-06 08:06:07 +01:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
2012-08-08 06:31:51 +02:00
|
|
|
try:
|
|
|
|
site = Site.objects.get_current()
|
2017-12-06 08:06:07 +01:00
|
|
|
except ImproperlyConfigured:
|
2012-08-08 06:31:51 +02:00
|
|
|
site = Site(domain='configure-django-sites.com')
|
2019-10-11 13:23:01 +02:00
|
|
|
if helpdesk_settings.HELPDESK_USE_HTTPS_IN_EMAIL_LINK:
|
2019-07-04 10:32:49 +02:00
|
|
|
protocol = 'https'
|
|
|
|
else:
|
|
|
|
protocol = 'http'
|
|
|
|
return u"%s://%s%s?ticket=%s&email=%s&key=%s" % (
|
|
|
|
protocol,
|
2008-08-19 10:50:38 +02:00
|
|
|
site.domain,
|
2015-12-22 10:10:00 +01:00
|
|
|
reverse('helpdesk:public_view'),
|
2008-08-19 10:50:38 +02:00
|
|
|
self.ticket_for_url,
|
2018-09-08 20:36:35 +02:00
|
|
|
self.submitter_email,
|
|
|
|
self.secret_key
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-16 01:26:24 +01:00
|
|
|
ticket_url = property(_get_ticket_url)
|
|
|
|
|
2008-01-21 02:02:12 +01:00
|
|
|
def _get_staff_url(self):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Returns a staff-only URL for this ticket, used when giving a URL to
|
|
|
|
a staff member (in emails etc)
|
|
|
|
"""
|
2008-01-21 02:02:12 +01:00
|
|
|
from django.contrib.sites.models import Site
|
2017-12-06 08:06:07 +01:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
2012-08-08 06:31:51 +02:00
|
|
|
try:
|
|
|
|
site = Site.objects.get_current()
|
2017-12-06 08:06:07 +01:00
|
|
|
except ImproperlyConfigured:
|
2012-08-08 06:31:51 +02:00
|
|
|
site = Site(domain='configure-django-sites.com')
|
2019-10-11 13:23:01 +02:00
|
|
|
if helpdesk_settings.HELPDESK_USE_HTTPS_IN_EMAIL_LINK:
|
2019-07-04 10:32:49 +02:00
|
|
|
protocol = 'https'
|
|
|
|
else:
|
|
|
|
protocol = 'http'
|
|
|
|
return u"%s://%s%s" % (
|
|
|
|
protocol,
|
2008-08-19 10:50:38 +02:00
|
|
|
site.domain,
|
2015-12-22 10:10:00 +01:00
|
|
|
reverse('helpdesk:view',
|
2016-10-23 22:09:17 +02:00
|
|
|
args=[self.id])
|
|
|
|
)
|
2008-01-21 02:02:12 +01:00
|
|
|
staff_url = property(_get_staff_url)
|
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
def _can_be_resolved(self):
|
|
|
|
"""
|
|
|
|
Returns a boolean.
|
|
|
|
True = any dependencies are resolved
|
|
|
|
False = There are non-resolved dependencies
|
|
|
|
"""
|
|
|
|
OPEN_STATUSES = (Ticket.OPEN_STATUS, Ticket.REOPENED_STATUS)
|
2016-10-21 17:14:12 +02:00
|
|
|
return TicketDependency.objects.filter(ticket=self).filter(
|
|
|
|
depends_on__status__in=OPEN_STATUSES).count() == 0
|
2011-05-10 11:27:11 +02:00
|
|
|
can_be_resolved = property(_can_be_resolved)
|
|
|
|
|
2018-08-20 01:08:45 +02:00
|
|
|
def get_submitter_userprofile(self):
|
|
|
|
User = get_user_model()
|
|
|
|
try:
|
|
|
|
return User.objects.get(email=self.submitter_email)
|
2020-10-08 22:34:45 +02:00
|
|
|
except (User.DoesNotExist, User.MultipleObjectsReturned):
|
2018-08-20 01:08:45 +02:00
|
|
|
return None
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Meta:
|
|
|
|
get_latest_by = "created"
|
2013-03-06 10:58:25 +01:00
|
|
|
ordering = ('id',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Ticket')
|
|
|
|
verbose_name_plural = _('Tickets')
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s %s' % (self.id, self.title)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
|
|
|
return reverse('helpdesk:view', args=(self.id,))
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
def save(self, *args, **kwargs):
|
2007-12-27 01:29:17 +01:00
|
|
|
if not self.id:
|
|
|
|
# This is a new ticket as no ID yet exists.
|
2013-01-23 00:59:12 +01:00
|
|
|
self.created = timezone.now()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
if not self.priority:
|
|
|
|
self.priority = 3
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2013-01-23 00:59:12 +01:00
|
|
|
self.modified = timezone.now()
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
super(Ticket, self).save(*args, **kwargs)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
@staticmethod
|
|
|
|
def queue_and_id_from_query(query):
|
2016-06-26 02:45:55 +02:00
|
|
|
# Apply the opposite logic here compared to self._get_ticket_for_url
|
|
|
|
# Ensure that queues with '-' in them will work
|
|
|
|
parts = query.split('-')
|
|
|
|
queue = '-'.join(parts[0:-1])
|
|
|
|
return queue, parts[-1]
|
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
def get_markdown(self):
|
|
|
|
return get_markdown(self.description)
|
|
|
|
|
2019-03-29 15:17:10 +01:00
|
|
|
@property
|
|
|
|
def get_resolution_markdown(self):
|
|
|
|
return get_markdown(self.resolution)
|
|
|
|
|
2020-10-29 23:32:02 +01:00
|
|
|
def add_email_to_ticketcc_if_not_in(self, email=None, user=None, ticketcc=None):
|
|
|
|
"""
|
|
|
|
Check that given email/user_email/ticketcc_email is not already present on the ticket
|
|
|
|
(submitter email, assigned to, or in ticket CCs) and add it to a new ticket CC,
|
|
|
|
or move the given one
|
|
|
|
|
|
|
|
:param str email:
|
|
|
|
:param User user:
|
|
|
|
:param TicketCC ticketcc:
|
2020-10-31 17:54:29 +01:00
|
|
|
:rtype: TicketCC|None
|
2020-10-29 23:32:02 +01:00
|
|
|
"""
|
|
|
|
if ticketcc:
|
|
|
|
email = ticketcc.display
|
|
|
|
elif user:
|
|
|
|
if user.email:
|
|
|
|
email = user.email
|
|
|
|
else:
|
2020-10-31 17:54:29 +01:00
|
|
|
# Ignore if user has no email address
|
2020-10-29 23:32:02 +01:00
|
|
|
return
|
|
|
|
elif not email:
|
2020-10-31 17:54:29 +01:00
|
|
|
raise ValueError('You must provide at least one parameter to get the email from')
|
|
|
|
|
|
|
|
# Prepare all emails already into the ticket
|
|
|
|
ticket_emails = [x.display for x in self.ticketcc_set.all()]
|
|
|
|
if self.submitter_email:
|
|
|
|
ticket_emails.append(self.submitter_email)
|
|
|
|
if self.assigned_to and self.assigned_to.email:
|
|
|
|
ticket_emails.append(self.assigned_to.email)
|
2020-10-29 23:32:02 +01:00
|
|
|
|
|
|
|
# Check that email is not already part of the ticket
|
2020-10-31 17:54:29 +01:00
|
|
|
if email not in ticket_emails:
|
2020-10-29 23:32:02 +01:00
|
|
|
if ticketcc:
|
|
|
|
ticketcc.ticket = self
|
|
|
|
ticketcc.save(update_fields=['ticket'])
|
|
|
|
elif user:
|
2020-10-31 17:54:29 +01:00
|
|
|
ticketcc = self.ticketcc_set.create(user=user)
|
2020-10-29 23:32:02 +01:00
|
|
|
else:
|
2020-10-31 17:54:29 +01:00
|
|
|
ticketcc = self.ticketcc_set.create(email=email)
|
|
|
|
return ticketcc
|
2020-10-29 23:32:02 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
class FollowUpManager(models.Manager):
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def private_followups(self):
|
|
|
|
return self.filter(public=False)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
def public_followups(self):
|
|
|
|
return self.filter(public=True)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class FollowUp(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
A FollowUp is a comment and/or change to a ticket. We keep a simple
|
|
|
|
title, the comment entered by the user, and the new status of a ticket
|
2007-12-27 02:35:34 +01:00
|
|
|
to enable easy flagging of details on the view-ticket page.
|
|
|
|
|
|
|
|
The title is automatically generated at save-time, based on what action
|
|
|
|
the user took.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
Tickets that aren't public are never shown to or e-mailed to the submitter,
|
2007-12-27 02:35:34 +01:00
|
|
|
although all staff can see them.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-01-29 07:10:12 +01:00
|
|
|
ticket = models.ForeignKey(
|
|
|
|
Ticket,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Ticket'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
date = models.DateTimeField(
|
2014-07-30 10:41:10 +02:00
|
|
|
_('Date'),
|
2016-10-23 22:09:17 +02:00
|
|
|
default=timezone.now
|
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=200,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
comment = models.TextField(
|
|
|
|
_('Comment'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
public = models.BooleanField(
|
|
|
|
_('Public'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2019-03-05 19:05:11 +01:00
|
|
|
help_text=_(
|
|
|
|
'Public tickets are viewable by the submitter and all '
|
|
|
|
'staff, but non-public tickets can only be seen by staff.'
|
|
|
|
),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
user = models.ForeignKey(
|
2014-09-10 01:06:50 +02:00
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2008-08-19 10:50:38 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('User'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
new_status = models.IntegerField(
|
|
|
|
_('New Status'),
|
|
|
|
choices=Ticket.STATUS_CHOICES,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('If the status was changed, what was it changed to?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2016-02-16 19:11:10 +01:00
|
|
|
message_id = models.CharField(
|
|
|
|
_('E-Mail ID'),
|
|
|
|
max_length=256,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_("The Message ID of the submitter's email."),
|
|
|
|
editable=False,
|
2018-12-28 17:32:49 +01:00
|
|
|
)
|
2016-02-16 19:11:10 +01:00
|
|
|
|
2008-01-16 01:26:24 +01:00
|
|
|
objects = FollowUpManager()
|
|
|
|
|
2019-02-06 14:24:43 +01:00
|
|
|
time_spent = models.DurationField(
|
|
|
|
help_text=_("Time spent on this follow up"),
|
|
|
|
blank=True, null=True
|
|
|
|
)
|
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class Meta:
|
2016-10-23 22:09:17 +02:00
|
|
|
ordering = ('date',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Follow-up')
|
|
|
|
verbose_name_plural = _('Follow-ups')
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.title
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-02-08 06:29:51 +01:00
|
|
|
def get_absolute_url(self):
|
2008-05-07 11:04:18 +02:00
|
|
|
return u"%s#followup%s" % (self.ticket.get_absolute_url(), self.id)
|
2008-02-08 06:29:51 +01:00
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
def save(self, *args, **kwargs):
|
2008-01-10 01:28:45 +01:00
|
|
|
t = self.ticket
|
2013-01-23 00:59:12 +01:00
|
|
|
t.modified = timezone.now()
|
2008-01-10 01:28:45 +01:00
|
|
|
t.save()
|
2012-01-14 13:06:37 +01:00
|
|
|
super(FollowUp, self).save(*args, **kwargs)
|
2008-01-10 01:28:45 +01:00
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
def get_markdown(self):
|
|
|
|
return get_markdown(self.comment)
|
|
|
|
|
2019-06-16 10:25:29 +02:00
|
|
|
@property
|
|
|
|
def time_spent_formated(self):
|
|
|
|
return format_time_spent(self.time_spent)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
class TicketChange(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
For each FollowUp, any changes to the parent ticket (eg Title, Priority,
|
2007-12-27 02:35:34 +01:00
|
|
|
etc) are tracked here for display purposes.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-01-29 07:10:12 +01:00
|
|
|
followup = models.ForeignKey(
|
|
|
|
FollowUp,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Follow-up'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
field = models.CharField(
|
|
|
|
_('Field'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
old_value = models.TextField(
|
|
|
|
_('Old Value'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
new_value = models.TextField(
|
|
|
|
_('New Value'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2007-12-27 02:35:34 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
out = '%s ' % self.field
|
2009-10-13 12:28:42 +02:00
|
|
|
if not self.new_value:
|
2015-11-18 15:26:08 +01:00
|
|
|
out += ugettext('removed')
|
2009-10-13 12:28:42 +02:00
|
|
|
elif not self.old_value:
|
2015-11-18 15:26:08 +01:00
|
|
|
out += ugettext('set to %s') % self.new_value
|
2007-12-27 02:35:34 +01:00
|
|
|
else:
|
2015-11-18 15:26:08 +01:00
|
|
|
out += ugettext('changed from "%(old_value)s" to "%(new_value)s"') % {
|
2009-10-13 12:28:42 +02:00
|
|
|
'old_value': self.old_value,
|
|
|
|
'new_value': self.new_value
|
2016-10-23 22:09:17 +02:00
|
|
|
}
|
2015-11-18 15:26:08 +01:00
|
|
|
return out
|
2008-01-07 21:22:13 +01:00
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Ticket change')
|
|
|
|
verbose_name_plural = _('Ticket changes')
|
|
|
|
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2008-12-30 01:41:47 +01:00
|
|
|
def attachment_path(instance, filename):
|
2019-03-07 21:58:04 +01:00
|
|
|
"""Just bridge"""
|
|
|
|
return instance.attachment_path(filename)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-02-08 01:19:58 +01:00
|
|
|
|
|
|
|
class Attachment(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
Represents a file attached to a follow-up. This could come from an e-mail
|
|
|
|
attachment, or it could be uploaded via the web interface.
|
|
|
|
"""
|
|
|
|
|
2008-12-30 01:41:47 +01:00
|
|
|
file = models.FileField(
|
2008-08-19 10:50:38 +02:00
|
|
|
_('File'),
|
2008-12-30 01:41:47 +01:00
|
|
|
upload_to=attachment_path,
|
2014-09-02 10:36:00 +02:00
|
|
|
max_length=1000,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
filename = models.CharField(
|
|
|
|
_('Filename'),
|
2019-03-07 21:58:04 +01:00
|
|
|
blank=True,
|
2014-09-02 10:36:00 +02:00
|
|
|
max_length=1000,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
mime_type = models.CharField(
|
|
|
|
_('MIME Type'),
|
2019-03-07 21:58:04 +01:00
|
|
|
blank=True,
|
2012-08-28 10:56:30 +02:00
|
|
|
max_length=255,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
size = models.IntegerField(
|
|
|
|
_('Size'),
|
2019-03-07 21:58:04 +01:00
|
|
|
blank=True,
|
2008-08-19 10:50:38 +02:00
|
|
|
help_text=_('Size of this file in bytes'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-15 05:00:19 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.filename
|
2008-01-15 05:00:19 +01:00
|
|
|
|
2019-03-07 21:58:04 +01:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
|
|
|
if not self.size:
|
|
|
|
self.size = self.get_size()
|
|
|
|
|
|
|
|
if not self.filename:
|
|
|
|
self.filename = self.get_filename()
|
|
|
|
|
|
|
|
if not self.mime_type:
|
|
|
|
self.mime_type = \
|
|
|
|
mimetypes.guess_type(self.filename, strict=False)[0] or \
|
|
|
|
'application/octet-stream'
|
|
|
|
|
|
|
|
return super(Attachment, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_filename(self):
|
|
|
|
return str(self.file)
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
return self.file.file.size
|
|
|
|
|
|
|
|
def attachment_path(self, filename):
|
|
|
|
"""Provide a file path that will help prevent files being overwritten, by
|
|
|
|
putting attachments in a folder off attachments for ticket/followup_id/.
|
|
|
|
"""
|
|
|
|
assert NotImplementedError(
|
|
|
|
"This method is to be implemented by Attachment classes"
|
|
|
|
)
|
|
|
|
|
2008-01-15 05:00:19 +01:00
|
|
|
class Meta:
|
2016-10-23 22:09:17 +02:00
|
|
|
ordering = ('filename',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Attachment')
|
|
|
|
verbose_name_plural = _('Attachments')
|
2019-03-07 21:58:04 +01:00
|
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
class FollowUpAttachment(Attachment):
|
|
|
|
|
|
|
|
followup = models.ForeignKey(
|
|
|
|
FollowUp,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_('Follow-up'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def attachment_path(self, filename):
|
|
|
|
|
|
|
|
os.umask(0)
|
|
|
|
path = 'helpdesk/attachments/{ticket_for_url}-{secret_key}/{id_}'.format(
|
|
|
|
ticket_for_url=self.followup.ticket.ticket_for_url,
|
|
|
|
secret_key=self.followup.ticket.secret_key,
|
|
|
|
id_=self.followup.id)
|
|
|
|
att_path = os.path.join(settings.MEDIA_ROOT, path)
|
|
|
|
if settings.DEFAULT_FILE_STORAGE == "django.core.files.storage.FileSystemStorage":
|
|
|
|
if not os.path.exists(att_path):
|
|
|
|
os.makedirs(att_path, 0o777)
|
|
|
|
return os.path.join(path, filename)
|
|
|
|
|
|
|
|
|
|
|
|
class KBIAttachment(Attachment):
|
|
|
|
|
|
|
|
kbitem = models.ForeignKey(
|
|
|
|
"KBItem",
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_('Knowledge base item'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def attachment_path(self, filename):
|
|
|
|
|
|
|
|
os.umask(0)
|
|
|
|
path = 'helpdesk/attachments/kb/{category}/{kbi}'.format(
|
|
|
|
category=self.kbitem.category,
|
|
|
|
kbi=self.kbitem.id)
|
|
|
|
att_path = os.path.join(settings.MEDIA_ROOT, path)
|
|
|
|
if settings.DEFAULT_FILE_STORAGE == "django.core.files.storage.FileSystemStorage":
|
|
|
|
if not os.path.exists(att_path):
|
|
|
|
os.makedirs(att_path, 0o777)
|
|
|
|
return os.path.join(path, filename)
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2008-01-11 02:00:01 +01:00
|
|
|
|
|
|
|
class PreSetReply(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
We can allow the admin to define a number of pre-set replies, used to
|
2008-01-15 01:20:00 +01:00
|
|
|
simplify the sending of updates and resolutions. These are basically Django
|
2008-08-19 10:50:38 +02:00
|
|
|
templates with a limited context - however if you wanted to get crafy it would
|
|
|
|
be easy to write a reply that displays ALL updates in hierarchical order etc
|
2008-01-15 01:20:00 +01:00
|
|
|
with use of for loops over {{ ticket.followup_set.all }} and friends.
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-15 01:20:00 +01:00
|
|
|
When replying to a ticket, the user can select any reply set for the current
|
2008-08-19 10:50:38 +02:00
|
|
|
queue, and the body text is fetched via AJAX.
|
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
class Meta:
|
2016-10-23 22:09:17 +02:00
|
|
|
ordering = ('name',)
|
2016-10-21 17:14:12 +02:00
|
|
|
verbose_name = _('Pre-set reply')
|
|
|
|
verbose_name_plural = _('Pre-set replies')
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
|
|
|
help_text=_('Leave blank to allow this reply to be used for all '
|
2016-10-21 17:14:12 +02:00
|
|
|
'queues, or select those queues you wish to limit this reply to.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('Only used to assist users with selecting a reply - not '
|
2016-10-21 17:14:12 +02:00
|
|
|
'shown to the user.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
body = models.TextField(
|
|
|
|
_('Body'),
|
|
|
|
help_text=_('Context available: {{ ticket }} - ticket object (eg '
|
2016-10-21 17:14:12 +02:00
|
|
|
'{{ ticket.title }}); {{ queue }} - The queue; and {{ user }} '
|
|
|
|
'- the current user.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-15 01:20:00 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.name
|
2008-01-22 06:54:22 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-22 06:54:22 +01:00
|
|
|
class EscalationExclusion(models.Model):
|
2008-08-19 10:50:38 +02:00
|
|
|
"""
|
|
|
|
An 'EscalationExclusion' lets us define a date on which escalation should
|
|
|
|
not happen, for example a weekend or public holiday.
|
2008-01-22 06:54:22 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
You may also have a queue that is only used on one day per week.
|
|
|
|
|
|
|
|
To create these on a regular basis, check out the README file for an
|
|
|
|
example cronjob that runs 'create_escalation_exclusions.py'.
|
|
|
|
"""
|
|
|
|
|
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Leave blank for this exclusion to be applied to all queues, '
|
|
|
|
'or select those queues you wish to exclude with this entry.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
date = models.DateField(
|
|
|
|
_('Date'),
|
|
|
|
help_text=_('Date on which escalation should not happen'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-01-22 06:54:22 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.name
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Escalation exclusion')
|
|
|
|
verbose_name_plural = _('Escalation exclusions')
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
class EmailTemplate(models.Model):
|
|
|
|
"""
|
|
|
|
Since these are more likely to be changed than other templates, we store
|
2008-08-19 10:50:38 +02:00
|
|
|
them in the database.
|
|
|
|
|
|
|
|
This means that an admin can change email templates without having to have
|
|
|
|
access to the filesystem.
|
2008-04-02 01:26:12 +02:00
|
|
|
"""
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
template_name = models.CharField(
|
|
|
|
_('Template Name'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
subject = models.CharField(
|
|
|
|
_('Subject'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('This will be prefixed with "[ticket.ticket] ticket.title"'
|
2016-10-21 17:14:12 +02:00
|
|
|
'. We recommend something simple such as "(Updated") or "(Closed)"'
|
|
|
|
' - the same context is available as in plain_text, below.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
heading = models.CharField(
|
|
|
|
_('Heading'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('In HTML e-mails, this will be the heading at the top of '
|
2016-10-21 17:14:12 +02:00
|
|
|
'the email - the same context is available as in plain_text, '
|
|
|
|
'below.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
plain_text = models.TextField(
|
|
|
|
_('Plain Text'),
|
|
|
|
help_text=_('The context available to you includes {{ ticket }}, '
|
2016-10-21 17:14:12 +02:00
|
|
|
'{{ queue }}, and depending on the time of the call: '
|
|
|
|
'{{ resolution }} or {{ comment }}.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
html = models.TextField(
|
|
|
|
_('HTML'),
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('The same context is available here as in plain_text, above.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2014-07-30 10:41:10 +02:00
|
|
|
|
2011-03-11 23:30:59 +01:00
|
|
|
locale = models.CharField(
|
|
|
|
_('Locale'),
|
|
|
|
max_length=10,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('Locale of this template.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.template_name
|
2008-04-02 01:26:12 +02:00
|
|
|
|
|
|
|
class Meta:
|
2016-10-23 22:09:17 +02:00
|
|
|
ordering = ('template_name', 'locale')
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('e-mail template')
|
|
|
|
verbose_name_plural = _('e-mail templates')
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
class KBCategory(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
Lets help users help themselves: the Knowledge Base is a categorised
|
2008-05-21 23:16:44 +02:00
|
|
|
listing of questions & answers.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2020-02-25 14:25:24 +01:00
|
|
|
name = models.CharField(
|
|
|
|
_('Name of the category'),
|
|
|
|
max_length=100,
|
|
|
|
)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
title = models.CharField(
|
2020-02-25 14:25:24 +01:00
|
|
|
_('Title on knowledgebase page'),
|
2008-08-19 10:50:38 +02:00
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
slug = models.SlugField(
|
|
|
|
_('Slug'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
description = models.TextField(
|
|
|
|
_('Description'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2020-01-06 14:25:37 +01:00
|
|
|
queue = models.ForeignKey(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_('Default queue when creating a ticket after viewing this category.'),
|
|
|
|
)
|
|
|
|
|
2020-01-27 17:37:59 +01:00
|
|
|
public = models.BooleanField(
|
|
|
|
default=True,
|
|
|
|
verbose_name=_("Is KBCategory publicly visible?")
|
|
|
|
)
|
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2020-02-25 14:25:24 +01:00
|
|
|
return '%s' % self.name
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
class Meta:
|
2016-10-23 22:09:17 +02:00
|
|
|
ordering = ('title',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Knowledge base category')
|
|
|
|
verbose_name_plural = _('Knowledge base categories')
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def get_absolute_url(self):
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
|
|
|
return reverse('helpdesk:kb_category', kwargs={'slug': self.slug})
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
class KBItem(models.Model):
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
An item within the knowledgebase. Very straightforward question/answer
|
2008-05-21 23:16:44 +02:00
|
|
|
style system.
|
|
|
|
"""
|
2020-01-07 13:26:02 +01:00
|
|
|
voted_by = models.ManyToManyField(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
related_name='votes',
|
|
|
|
)
|
|
|
|
downvoted_by = models.ManyToManyField(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
related_name='downvotes',
|
|
|
|
)
|
2011-01-29 07:10:12 +01:00
|
|
|
category = models.ForeignKey(
|
|
|
|
KBCategory,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Category'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
title = models.CharField(
|
|
|
|
_('Title'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
question = models.TextField(
|
|
|
|
_('Question'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
answer = models.TextField(
|
|
|
|
_('Answer'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
votes = models.IntegerField(
|
|
|
|
_('Votes'),
|
|
|
|
help_text=_('Total number of votes cast for this item'),
|
2011-02-03 23:15:03 +01:00
|
|
|
default=0,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
recommendations = models.IntegerField(
|
|
|
|
_('Positive Votes'),
|
|
|
|
help_text=_('Number of votes for this item which were POSITIVE.'),
|
2011-02-03 23:15:03 +01:00
|
|
|
default=0,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
last_updated = models.DateTimeField(
|
|
|
|
_('Last Updated'),
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('The date on which this question was most recently changed.'),
|
2008-10-07 08:52:52 +02:00
|
|
|
blank=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2020-01-27 17:37:59 +01:00
|
|
|
team = models.ForeignKey(
|
|
|
|
pinax.teams.models.Team,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_('Team'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
2020-02-25 14:43:10 +01:00
|
|
|
order = models.PositiveIntegerField(
|
|
|
|
_('Order'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
2020-02-25 14:46:21 +01:00
|
|
|
enabled = models.BooleanField(
|
|
|
|
_('Enabled to display to users'),
|
|
|
|
default=True,
|
|
|
|
)
|
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
def save(self, *args, **kwargs):
|
2008-10-07 08:52:52 +02:00
|
|
|
if not self.last_updated:
|
2013-01-23 00:59:12 +01:00
|
|
|
self.last_updated = timezone.now()
|
2012-01-14 13:06:37 +01:00
|
|
|
return super(KBItem, self).save(*args, **kwargs)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
def _score(self):
|
2020-06-29 14:38:41 +02:00
|
|
|
""" Return a score out of 10 or Unrated if no votes """
|
2008-05-21 23:16:44 +02:00
|
|
|
if self.votes > 0:
|
2020-06-29 14:38:41 +02:00
|
|
|
return (self.recommendations / self.votes) * 10
|
2008-05-21 23:16:44 +02:00
|
|
|
else:
|
|
|
|
return _('Unrated')
|
|
|
|
score = property(_score)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2020-02-11 15:20:16 +01:00
|
|
|
return '%s: %s' % (self.category.title, self.title)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
class Meta:
|
2020-02-25 14:43:10 +01:00
|
|
|
ordering = ('order', 'title',)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Knowledge base item')
|
|
|
|
verbose_name_plural = _('Knowledge base items')
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
def get_absolute_url(self):
|
2017-12-28 15:11:34 +01:00
|
|
|
from django.urls import reverse
|
2020-01-08 20:38:08 +01:00
|
|
|
return str(reverse('helpdesk:kb_category', args=(self.category.slug,))) + "?kbitem=" + str(self.pk)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2020-01-08 18:39:41 +01:00
|
|
|
def query_url(self):
|
|
|
|
from django.urls import reverse
|
2020-01-08 20:38:08 +01:00
|
|
|
return str(reverse('helpdesk:list')) + "?kbitem=" + str(self.pk)
|
2020-01-08 18:39:41 +01:00
|
|
|
|
2020-01-08 22:57:08 +01:00
|
|
|
def num_open_tickets(self):
|
|
|
|
return Ticket.objects.filter(kbitem=self, status__in=(1, 2)).count()
|
|
|
|
|
2020-01-27 19:45:15 +01:00
|
|
|
def unassigned_tickets(self):
|
|
|
|
return Ticket.objects.filter(kbitem=self, status__in=(1, 2), assigned_to__isnull=True)
|
|
|
|
|
2019-03-05 19:05:11 +01:00
|
|
|
def get_markdown(self):
|
|
|
|
return get_markdown(self.answer)
|
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
|
|
|
|
class SavedSearch(models.Model):
|
|
|
|
"""
|
|
|
|
Allow a user to save a ticket search, eg their filtering and sorting
|
2014-07-30 10:41:10 +02:00
|
|
|
options, and optionally share it with other users. This lets people
|
2008-08-28 11:06:24 +02:00
|
|
|
easily create a set of commonly-used filters, such as:
|
|
|
|
* My tickets waiting on me
|
|
|
|
* My tickets waiting on submitter
|
|
|
|
* My tickets in 'Priority Support' queue with priority of 1
|
|
|
|
* All tickets containing the word 'billing'.
|
|
|
|
etc...
|
|
|
|
"""
|
2011-01-29 07:10:12 +01:00
|
|
|
user = models.ForeignKey(
|
2014-09-10 01:06:50 +02:00
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('User'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-28 11:06:24 +02:00
|
|
|
|
|
|
|
title = models.CharField(
|
|
|
|
_('Query Name'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('User-provided name for this query'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-28 11:06:24 +02:00
|
|
|
|
|
|
|
shared = models.BooleanField(
|
|
|
|
_('Shared With Other Users?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2008-08-28 11:06:24 +02:00
|
|
|
help_text=_('Should other users see this query?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
query = models.TextField(
|
|
|
|
_('Search Query'),
|
|
|
|
help_text=_('Pickled query object. Be wary changing this.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-08-28 11:06:24 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2008-08-28 11:06:24 +02:00
|
|
|
if self.shared:
|
2015-11-18 15:26:08 +01:00
|
|
|
return '%s (*)' % self.title
|
2008-08-28 11:06:24 +02:00
|
|
|
else:
|
2015-11-18 15:26:08 +01:00
|
|
|
return '%s' % self.title
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Saved search')
|
|
|
|
verbose_name_plural = _('Saved searches')
|
|
|
|
|
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
def get_default_setting(setting):
|
|
|
|
from helpdesk.settings import DEFAULT_USER_SETTINGS
|
|
|
|
return DEFAULT_USER_SETTINGS[setting]
|
|
|
|
|
|
|
|
|
|
|
|
def login_view_ticketlist_default():
|
|
|
|
return get_default_setting('login_view_ticketlist')
|
|
|
|
|
|
|
|
|
|
|
|
def email_on_ticket_change_default():
|
|
|
|
return get_default_setting('email_on_ticket_change')
|
|
|
|
|
|
|
|
|
|
|
|
def email_on_ticket_assign_default():
|
|
|
|
return get_default_setting('email_on_ticket_assign')
|
|
|
|
|
|
|
|
|
|
|
|
def tickets_per_page_default():
|
|
|
|
return get_default_setting('tickets_per_page')
|
|
|
|
|
|
|
|
|
|
|
|
def use_email_as_submitter_default():
|
|
|
|
return get_default_setting('use_email_as_submitter')
|
|
|
|
|
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
class UserSettings(models.Model):
|
|
|
|
"""
|
|
|
|
A bunch of user-specific settings that we want to be able to define, such
|
2014-07-30 10:41:10 +02:00
|
|
|
as notification preferences and other things that should probably be
|
2008-09-09 10:32:01 +02:00
|
|
|
configurable.
|
|
|
|
"""
|
2018-10-05 14:54:22 +02:00
|
|
|
PAGE_SIZES = ((10, '10'), (25, '25'), (50, '50'), (100, '100'))
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2017-01-13 15:14:23 +01:00
|
|
|
user = models.OneToOneField(
|
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2017-01-13 15:14:23 +01:00
|
|
|
related_name="usersettings_helpdesk")
|
2008-09-09 10:32:01 +02:00
|
|
|
|
|
|
|
settings_pickled = models.TextField(
|
2018-10-05 14:54:22 +02:00
|
|
|
_('DEPRECATED! Settings Dictionary DEPRECATED!'),
|
|
|
|
help_text=_('DEPRECATED! This is a base64-encoded representation of a pickled Python dictionary. '
|
2016-10-21 17:14:12 +02:00
|
|
|
'Do not change this field via the admin.'),
|
2008-09-09 10:32:01 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
login_view_ticketlist = models.BooleanField(
|
|
|
|
verbose_name=_('Show Ticket List on Login?'),
|
|
|
|
help_text=_('Display the ticket list upon login? Otherwise, the dashboard is shown.'),
|
|
|
|
default=login_view_ticketlist_default,
|
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
email_on_ticket_change = models.BooleanField(
|
|
|
|
verbose_name=_('E-mail me on ticket change?'),
|
|
|
|
help_text=_('If you\'re the ticket owner and the ticket is changed via the web by somebody else, do you want to receive an e-mail?'),
|
|
|
|
default=email_on_ticket_change_default,
|
|
|
|
)
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
email_on_ticket_assign = models.BooleanField(
|
|
|
|
verbose_name=_('E-mail me when assigned a ticket?'),
|
|
|
|
help_text=_('If you are assigned a ticket via the web, do you want to receive an e-mail?'),
|
|
|
|
default=email_on_ticket_assign_default,
|
|
|
|
)
|
|
|
|
|
|
|
|
tickets_per_page = models.IntegerField(
|
|
|
|
verbose_name=_('Number of tickets to show per page'),
|
|
|
|
help_text=_('How many tickets do you want to see on the Ticket List page?'),
|
|
|
|
default=tickets_per_page_default,
|
|
|
|
choices=PAGE_SIZES,
|
|
|
|
)
|
|
|
|
|
|
|
|
use_email_as_submitter = models.BooleanField(
|
|
|
|
verbose_name=_('Use my e-mail address when submitting tickets?'),
|
|
|
|
help_text=_('When you submit a ticket, do you want to automatically '
|
|
|
|
'use your e-mail address as the submitter address? You '
|
|
|
|
'can type a different e-mail address when entering the '
|
|
|
|
'ticket if needed, this option only changes the default.'),
|
|
|
|
default=use_email_as_submitter_default,
|
|
|
|
)
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return 'Preferences for %s' % self.user
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-09-09 10:32:01 +02:00
|
|
|
class Meta:
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('User Setting')
|
|
|
|
verbose_name_plural = _('User Settings')
|
2008-09-09 10:32:01 +02:00
|
|
|
|
|
|
|
|
2015-01-14 11:15:45 +01:00
|
|
|
def create_usersettings(sender, instance, created, **kwargs):
|
2008-09-09 10:32:01 +02:00
|
|
|
"""
|
2014-07-30 10:41:10 +02:00
|
|
|
Helper function to create UserSettings instances as
|
2008-09-09 10:32:01 +02:00
|
|
|
required, eg when we first create the UserSettings database
|
|
|
|
table via 'syncdb' or when we save a new user.
|
|
|
|
|
|
|
|
If we end up with users with no UserSettings, then we get horrible
|
|
|
|
'DoesNotExist: UserSettings matching query does not exist.' errors.
|
|
|
|
"""
|
2015-01-14 11:15:45 +01:00
|
|
|
if created:
|
2018-10-05 14:54:22 +02:00
|
|
|
UserSettings.objects.create(user=instance)
|
2015-01-14 11:15:45 +01:00
|
|
|
|
2017-12-06 08:06:07 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
models.signals.post_save.connect(create_usersettings, sender=settings.AUTH_USER_MODEL)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
2015-01-14 11:15:45 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
class IgnoreEmail(models.Model):
|
|
|
|
"""
|
2014-07-30 10:41:10 +02:00
|
|
|
This model lets us easily ignore e-mails from certain senders when
|
|
|
|
processing IMAP and POP3 mailboxes, eg mails from postmaster or from
|
2008-10-25 00:52:34 +02:00
|
|
|
known trouble-makers.
|
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Ignored e-mail address')
|
|
|
|
verbose_name_plural = _('Ignored e-mail addresses')
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
queues = models.ManyToManyField(
|
|
|
|
Queue,
|
|
|
|
blank=True,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Leave blank for this e-mail to be ignored on all queues, '
|
|
|
|
'or select those queues you wish to ignore this e-mail for.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
|
|
|
name = models.CharField(
|
|
|
|
_('Name'),
|
|
|
|
max_length=100,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
date = models.DateField(
|
|
|
|
_('Date'),
|
|
|
|
help_text=_('Date on which this e-mail address was added'),
|
|
|
|
blank=True,
|
|
|
|
editable=False
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
|
|
|
email_address = models.CharField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
max_length=150,
|
|
|
|
help_text=_('Enter a full e-mail address, or portions with '
|
2016-10-21 17:14:12 +02:00
|
|
|
'wildcards, eg *@domain.com or postmaster@*.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
2009-01-23 11:36:41 +01:00
|
|
|
keep_in_mailbox = models.BooleanField(
|
|
|
|
_('Save Emails in Mailbox?'),
|
|
|
|
blank=True,
|
2009-05-24 07:26:12 +02:00
|
|
|
default=False,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Do you want to save emails from this address in the mailbox? '
|
|
|
|
'If this is unticked, emails from this address will be deleted.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s' % self.name
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2012-01-14 13:06:37 +01:00
|
|
|
def save(self, *args, **kwargs):
|
2008-10-25 00:52:34 +02:00
|
|
|
if not self.date:
|
2013-01-23 00:59:12 +01:00
|
|
|
self.date = timezone.now()
|
2012-01-14 13:06:37 +01:00
|
|
|
return super(IgnoreEmail, self).save(*args, **kwargs)
|
2008-10-25 00:52:34 +02:00
|
|
|
|
2017-06-19 20:34:36 +02:00
|
|
|
def queue_list(self):
|
|
|
|
"""Return a list of the queues this IgnoreEmail applies to.
|
|
|
|
If this IgnoreEmail applies to ALL queues, return '*'.
|
|
|
|
"""
|
|
|
|
queues = self.queues.all().order_by('title')
|
|
|
|
if len(queues) == 0:
|
|
|
|
return '*'
|
|
|
|
else:
|
|
|
|
return ', '.join([str(q) for q in queues])
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
def test(self, email):
|
|
|
|
"""
|
|
|
|
Possible situations:
|
|
|
|
1. Username & Domain both match
|
|
|
|
2. Username is wildcard, domain matches
|
|
|
|
3. Username matches, domain is wildcard
|
|
|
|
4. username & domain are both wildcards
|
|
|
|
5. Other (no match)
|
|
|
|
|
|
|
|
1-4 return True, 5 returns False.
|
|
|
|
"""
|
2009-01-23 11:36:41 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
own_parts = self.email_address.split("@")
|
|
|
|
email_parts = email.split("@")
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
if self.email_address == email or \
|
|
|
|
own_parts[0] == "*" and own_parts[1] == email_parts[1] or \
|
|
|
|
own_parts[1] == "*" and own_parts[0] == email_parts[0] or \
|
|
|
|
own_parts[0] == "*" and own_parts[1] == "*":
|
2008-10-25 00:52:34 +02:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2009-09-09 10:47:48 +02:00
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
class TicketCC(models.Model):
|
|
|
|
"""
|
2014-07-30 10:41:10 +02:00
|
|
|
Often, there are people who wish to follow a ticket who aren't the
|
2009-09-09 10:47:48 +02:00
|
|
|
person who originally submitted it. This model provides a way for those
|
|
|
|
people to follow a ticket.
|
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
In this circumstance, a 'person' could be either an e-mail address or
|
2009-09-09 10:47:48 +02:00
|
|
|
an existing system user.
|
|
|
|
"""
|
|
|
|
|
2011-01-29 07:10:12 +01:00
|
|
|
ticket = models.ForeignKey(
|
|
|
|
Ticket,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('Ticket'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
user = models.ForeignKey(
|
2014-09-10 01:06:50 +02:00
|
|
|
settings.AUTH_USER_MODEL,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2009-09-09 10:47:48 +02:00
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('User who wishes to receive updates for this ticket.'),
|
2011-01-29 07:10:12 +01:00
|
|
|
verbose_name=_('User'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
email = models.EmailField(
|
|
|
|
_('E-Mail Address'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
help_text=_('For non-user followers, enter their e-mail address'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
can_view = models.BooleanField(
|
|
|
|
_('Can View Ticket?'),
|
|
|
|
blank=True,
|
2014-09-10 01:06:50 +02:00
|
|
|
default=False,
|
2009-09-09 10:47:48 +02:00
|
|
|
help_text=_('Can this CC login to view the ticket details?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
can_update = models.BooleanField(
|
|
|
|
_('Can Update Ticket?'),
|
|
|
|
blank=True,
|
2014-09-10 01:06:50 +02:00
|
|
|
default=False,
|
2009-09-09 10:47:48 +02:00
|
|
|
help_text=_('Can this CC login and update the ticket?'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
|
|
|
def _email_address(self):
|
|
|
|
if self.user and self.user.email is not None:
|
|
|
|
return self.user.email
|
|
|
|
else:
|
|
|
|
return self.email
|
|
|
|
email_address = property(_email_address)
|
|
|
|
|
|
|
|
def _display(self):
|
|
|
|
if self.user:
|
|
|
|
return self.user
|
|
|
|
else:
|
|
|
|
return self.email
|
|
|
|
display = property(_display)
|
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
|
|
|
return '%s for %s' % (self.display, self.ticket.title)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2020-10-31 18:24:22 +01:00
|
|
|
def clean(self):
|
|
|
|
if self.user and not self.user.email:
|
|
|
|
raise ValidationError('User has no email address')
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2011-11-08 07:59:34 +01:00
|
|
|
class CustomFieldManager(models.Manager):
|
2016-10-23 22:09:17 +02:00
|
|
|
|
2014-09-10 01:06:50 +02:00
|
|
|
def get_queryset(self):
|
|
|
|
return super(CustomFieldManager, self).get_queryset().order_by('ordering')
|
2011-11-08 07:59:34 +01:00
|
|
|
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
class CustomField(models.Model):
|
|
|
|
"""
|
|
|
|
Definitions for custom fields that are glued onto each ticket.
|
|
|
|
"""
|
|
|
|
|
|
|
|
name = models.SlugField(
|
|
|
|
_('Field Name'),
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('As used in the database and behind the scenes. '
|
|
|
|
'Must be unique and consist of only lowercase letters with no punctuation.'),
|
2011-02-02 12:22:46 +01:00
|
|
|
unique=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
label = models.CharField(
|
|
|
|
_('Label'),
|
2015-12-15 10:11:47 +01:00
|
|
|
max_length=30,
|
2011-02-02 12:22:46 +01:00
|
|
|
help_text=_('The display label for this field'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
help_text = models.TextField(
|
|
|
|
_('Help Text'),
|
|
|
|
help_text=_('Shown to the user when editing the ticket'),
|
2011-02-02 12:37:38 +01:00
|
|
|
blank=True,
|
|
|
|
null=True
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
DATA_TYPE_CHOICES = (
|
2016-10-23 22:09:17 +02:00
|
|
|
('varchar', _('Character (single line)')),
|
|
|
|
('text', _('Text (multi-line)')),
|
|
|
|
('integer', _('Integer')),
|
|
|
|
('decimal', _('Decimal')),
|
|
|
|
('list', _('List')),
|
|
|
|
('boolean', _('Boolean (checkbox yes/no)')),
|
|
|
|
('date', _('Date')),
|
|
|
|
('time', _('Time')),
|
|
|
|
('datetime', _('Date & Time')),
|
|
|
|
('email', _('E-Mail Address')),
|
|
|
|
('url', _('URL')),
|
|
|
|
('ipaddress', _('IP Address')),
|
|
|
|
('slug', _('Slug')),
|
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
data_type = models.CharField(
|
|
|
|
_('Data Type'),
|
|
|
|
max_length=100,
|
|
|
|
help_text=_('Allows you to restrict the data entered into this field'),
|
|
|
|
choices=DATA_TYPE_CHOICES,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
max_length = models.IntegerField(
|
|
|
|
_('Maximum Length (characters)'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
decimal_places = models.IntegerField(
|
|
|
|
_('Decimal Places'),
|
|
|
|
help_text=_('Only used for decimal fields'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2014-07-30 10:41:10 +02:00
|
|
|
|
2011-12-01 20:48:37 +01:00
|
|
|
empty_selection_list = models.BooleanField(
|
|
|
|
_('Add empty first choice to List?'),
|
2014-06-05 02:19:46 +02:00
|
|
|
default=False,
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('Only for List: adds an empty first entry to the choices list, '
|
|
|
|
'which enforces that the user makes an active choice.'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
list_values = models.TextField(
|
|
|
|
_('List Values'),
|
|
|
|
help_text=_('For list fields only. Enter one option per line.'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2014-07-30 10:41:10 +02:00
|
|
|
|
2011-11-08 07:59:34 +01:00
|
|
|
ordering = models.IntegerField(
|
|
|
|
_('Ordering'),
|
|
|
|
help_text=_('Lower numbers are displayed first; higher numbers are listed later'),
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2011-05-03 00:32:15 +02:00
|
|
|
def _choices_as_array(self):
|
|
|
|
valuebuffer = StringIO(self.list_values)
|
|
|
|
choices = [[item.strip(), item.strip()] for item in valuebuffer.readlines()]
|
|
|
|
valuebuffer.close()
|
|
|
|
return choices
|
|
|
|
choices_as_array = property(_choices_as_array)
|
|
|
|
|
2011-02-02 12:22:46 +01:00
|
|
|
required = models.BooleanField(
|
|
|
|
_('Required?'),
|
|
|
|
help_text=_('Does the user have to enter a value for this field?'),
|
2014-09-10 01:06:50 +02:00
|
|
|
default=False,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
staff_only = models.BooleanField(
|
|
|
|
_('Staff Only?'),
|
2016-10-21 17:14:12 +02:00
|
|
|
help_text=_('If this is ticked, then the public submission form '
|
|
|
|
'will NOT show this field'),
|
2014-09-10 01:06:50 +02:00
|
|
|
default=False,
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2011-11-08 07:59:34 +01:00
|
|
|
objects = CustomFieldManager()
|
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2016-10-21 17:14:12 +02:00
|
|
|
return '%s' % self.name
|
2011-02-02 12:22:46 +01:00
|
|
|
|
2014-07-30 10:41:10 +02:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _('Custom field')
|
|
|
|
verbose_name_plural = _('Custom fields')
|
|
|
|
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
class TicketCustomFieldValue(models.Model):
|
|
|
|
ticket = models.ForeignKey(
|
|
|
|
Ticket,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-02-02 12:22:46 +01:00
|
|
|
verbose_name=_('Ticket'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
field = models.ForeignKey(
|
|
|
|
CustomField,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-02-02 12:22:46 +01:00
|
|
|
verbose_name=_('Field'),
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-02-02 12:22:46 +01:00
|
|
|
|
|
|
|
value = models.TextField(blank=True, null=True)
|
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2011-02-02 12:22:46 +01:00
|
|
|
return '%s / %s' % (self.ticket, self.field)
|
|
|
|
|
|
|
|
class Meta:
|
2016-10-07 11:00:25 +02:00
|
|
|
unique_together = (('ticket', 'field'),)
|
2014-07-30 10:41:10 +02:00
|
|
|
verbose_name = _('Ticket custom field value')
|
|
|
|
verbose_name_plural = _('Ticket custom field values')
|
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
|
|
|
|
class TicketDependency(models.Model):
|
|
|
|
"""
|
|
|
|
The ticket identified by `ticket` cannot be resolved until the ticket in `depends_on` has been resolved.
|
2014-07-30 10:41:10 +02:00
|
|
|
To help enforce this, a helper function `can_be_resolved` on each Ticket instance checks that
|
2011-05-10 11:27:11 +02:00
|
|
|
these have all been resolved.
|
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
class Meta:
|
|
|
|
unique_together = (('ticket', 'depends_on'),)
|
|
|
|
verbose_name = _('Ticket dependency')
|
|
|
|
verbose_name_plural = _('Ticket dependencies')
|
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
ticket = models.ForeignKey(
|
|
|
|
Ticket,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-05-10 11:27:11 +02:00
|
|
|
verbose_name=_('Ticket'),
|
|
|
|
related_name='ticketdependency',
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-05-10 11:27:11 +02:00
|
|
|
|
|
|
|
depends_on = models.ForeignKey(
|
|
|
|
Ticket,
|
2017-12-28 13:23:51 +01:00
|
|
|
on_delete=models.CASCADE,
|
2011-05-10 11:27:11 +02:00
|
|
|
verbose_name=_('Depends On Ticket'),
|
|
|
|
related_name='depends_on',
|
2016-10-23 22:09:17 +02:00
|
|
|
)
|
2011-05-10 11:27:11 +02:00
|
|
|
|
2015-11-18 15:26:08 +01:00
|
|
|
def __str__(self):
|
2011-05-10 11:27:11 +02:00
|
|
|
return '%s / %s' % (self.ticket, self.depends_on)
|