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.
|
2007-12-27 01:29:17 +01:00
|
|
|
|
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-08-19 10:50:38 +02:00
|
|
|
views/staff.py - The bulk of the application - provides most business logic and
|
2008-05-21 23:16:44 +02:00
|
|
|
renders all staff-facing views.
|
2007-12-27 01:29:17 +01:00
|
|
|
"""
|
2019-10-08 15:35:07 +02:00
|
|
|
from copy import deepcopy
|
2019-10-11 12:41:06 +02:00
|
|
|
import json
|
2019-10-08 15:35:07 +02:00
|
|
|
|
2009-01-20 09:12:05 +01:00
|
|
|
from django.conf import settings
|
2016-10-21 17:14:12 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.decorators import user_passes_test
|
2018-08-20 01:08:45 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2018-10-05 14:54:22 +02:00
|
|
|
from django.urls import reverse, reverse_lazy
|
2015-12-16 17:51:15 +01:00
|
|
|
from django.core.exceptions import ValidationError, PermissionDenied
|
2020-06-02 01:14:55 +02:00
|
|
|
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
2007-12-27 01:29:17 +01:00
|
|
|
from django.db.models import Q
|
2019-10-11 15:50:35 +02:00
|
|
|
from django.http import HttpResponseRedirect, Http404, HttpResponse, JsonResponse
|
2016-06-21 07:18:06 +02:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
2008-05-07 11:04:18 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2011-01-29 07:02:03 +01:00
|
|
|
from django.utils.html import escape
|
2016-11-21 03:12:19 +01:00
|
|
|
from django.utils import timezone
|
2018-10-05 14:54:22 +02:00
|
|
|
from django.views.generic.edit import FormView, UpdateView
|
2018-12-28 09:13:52 +01:00
|
|
|
|
2019-10-11 16:31:52 +02:00
|
|
|
from helpdesk.query import (
|
2019-10-30 19:34:58 +01:00
|
|
|
get_query_class,
|
2019-10-11 16:31:52 +02:00
|
|
|
query_to_base64,
|
|
|
|
query_from_base64,
|
|
|
|
)
|
2019-10-11 12:41:06 +02:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
from helpdesk.user import HelpdeskUser
|
|
|
|
|
2017-10-30 08:41:49 +01:00
|
|
|
from helpdesk.decorators import (
|
|
|
|
helpdesk_staff_member_required, helpdesk_superuser_required,
|
|
|
|
is_helpdesk_staff
|
|
|
|
)
|
2016-10-21 17:14:12 +02:00
|
|
|
from helpdesk.forms import (
|
|
|
|
TicketForm, UserSettingsForm, EmailIgnoreForm, EditTicketForm, TicketCCForm,
|
2016-10-29 09:47:15 +02:00
|
|
|
TicketCCEmailForm, TicketCCUserForm, EditFollowUpForm, TicketDependencyForm
|
2016-10-21 17:14:12 +02:00
|
|
|
)
|
2020-10-08 22:07:49 +02:00
|
|
|
from helpdesk.decorators import superuser_required
|
2016-10-21 17:14:12 +02:00
|
|
|
from helpdesk.lib import (
|
2019-10-11 16:31:52 +02:00
|
|
|
safe_template_context,
|
|
|
|
process_attachments,
|
|
|
|
queue_template_context,
|
2016-10-21 17:14:12 +02:00
|
|
|
)
|
|
|
|
from helpdesk.models import (
|
2019-03-07 21:58:04 +01:00
|
|
|
Ticket, Queue, FollowUp, TicketChange, PreSetReply, FollowUpAttachment, SavedSearch,
|
2020-01-08 18:39:41 +01:00
|
|
|
IgnoreEmail, TicketCC, TicketDependency, UserSettings, KBItem,
|
2016-10-21 17:14:12 +02:00
|
|
|
)
|
2011-11-19 09:34:07 +01:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
2020-01-08 18:39:41 +01:00
|
|
|
import helpdesk.views.abstract_views as abstract_views
|
2018-09-07 19:05:16 +02:00
|
|
|
from helpdesk.views.permissions import MustBeStaffMixin
|
2019-06-16 10:25:29 +02:00
|
|
|
from ..lib import format_time_spent
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2020-10-08 22:07:49 +02:00
|
|
|
from rest_framework import status
|
2018-12-28 09:13:52 +01:00
|
|
|
from rest_framework.decorators import api_view
|
|
|
|
|
|
|
|
from datetime import date, datetime, timedelta
|
|
|
|
import re
|
|
|
|
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
User = get_user_model()
|
2019-10-30 19:34:58 +01:00
|
|
|
Query = get_query_class()
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2011-11-19 09:34:07 +01:00
|
|
|
if helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE:
|
|
|
|
# treat 'normal' users like 'staff'
|
2016-10-21 17:14:12 +02:00
|
|
|
staff_member_required = user_passes_test(
|
2017-12-28 13:23:51 +01:00
|
|
|
lambda u: u.is_authenticated and u.is_active)
|
2011-11-19 09:34:07 +01:00
|
|
|
else:
|
2016-10-21 17:14:12 +02:00
|
|
|
staff_member_required = user_passes_test(
|
2017-12-28 13:23:51 +01:00
|
|
|
lambda u: u.is_authenticated and u.is_active and u.is_staff)
|
2011-11-19 09:34:07 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
|
2019-03-20 13:47:57 +01:00
|
|
|
User = get_user_model()
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2019-02-05 14:38:41 +01:00
|
|
|
def _get_queue_choices(queues):
|
|
|
|
"""Return list of `choices` array for html form for given queues
|
|
|
|
|
|
|
|
idea is to return only one choice if there is only one queue or add empty
|
|
|
|
choice at the beginning of the list, if there are more queues
|
|
|
|
"""
|
|
|
|
|
|
|
|
queue_choices = []
|
|
|
|
if len(queues) > 1:
|
|
|
|
queue_choices = [('', '--------')]
|
|
|
|
queue_choices += [(q.id, q.title) for q in queues]
|
|
|
|
return queue_choices
|
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2007-12-27 01:29:17 +01:00
|
|
|
def dashboard(request):
|
2008-01-16 01:26:24 +01:00
|
|
|
"""
|
2008-05-21 23:16:44 +02:00
|
|
|
A quick summary overview for users: A list of their own tickets, a table
|
2008-08-19 10:50:38 +02:00
|
|
|
showing ticket counts by queue/status, and a list of unassigned tickets
|
2008-05-21 23:16:44 +02:00
|
|
|
with options for them to 'Take' ownership of said tickets.
|
2008-01-16 01:26:24 +01:00
|
|
|
"""
|
2020-10-08 22:07:49 +02:00
|
|
|
# user settings num tickets per page
|
2020-10-08 22:34:40 +02:00
|
|
|
tickets_per_page = request.user.usersettings_helpdesk.tickets_per_page or 25
|
2020-10-08 22:07:49 +02:00
|
|
|
|
|
|
|
# page vars for the three ticket tables
|
|
|
|
user_tickets_page = request.GET.get(_('ut_page'), 1)
|
|
|
|
user_tickets_closed_resolved_page = request.GET.get(_('utcr_page'), 1)
|
|
|
|
all_tickets_reported_by_current_user_page = request.GET.get(_('atrbcu_page'), 1)
|
|
|
|
|
2020-01-27 19:45:15 +01:00
|
|
|
huser = HelpdeskUser(request.user)
|
2019-03-27 17:16:33 +01:00
|
|
|
active_tickets = Ticket.objects.select_related('queue').exclude(
|
|
|
|
status__in=[Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS],
|
|
|
|
)
|
|
|
|
|
2011-11-29 14:08:08 +01:00
|
|
|
# open & reopened tickets, assigned to current user
|
2019-03-27 17:16:33 +01:00
|
|
|
tickets = active_tickets.filter(
|
2016-10-23 22:02:02 +02:00
|
|
|
assigned_to=request.user,
|
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-11-29 14:08:08 +01:00
|
|
|
# closed & resolved tickets, assigned to current user
|
2016-10-21 17:14:12 +02:00
|
|
|
tickets_closed_resolved = Ticket.objects.select_related('queue').filter(
|
2016-10-23 22:02:02 +02:00
|
|
|
assigned_to=request.user,
|
|
|
|
status__in=[Ticket.CLOSED_STATUS, Ticket.RESOLVED_STATUS])
|
2011-11-19 09:34:07 +01:00
|
|
|
|
2020-01-27 19:45:15 +01:00
|
|
|
user_queues = huser.get_queues()
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2019-03-27 17:16:33 +01:00
|
|
|
unassigned_tickets = active_tickets.filter(
|
2016-10-23 22:02:02 +02:00
|
|
|
assigned_to__isnull=True,
|
2020-01-27 19:45:15 +01:00
|
|
|
kbitem__isnull=True,
|
2016-10-23 22:02:02 +02:00
|
|
|
queue__in=user_queues
|
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2020-01-27 19:45:15 +01:00
|
|
|
kbitems = huser.get_assigned_kb_items()
|
|
|
|
|
2011-11-29 14:08:08 +01:00
|
|
|
# all tickets, reported by current user
|
|
|
|
all_tickets_reported_by_current_user = ''
|
|
|
|
email_current_user = request.user.email
|
|
|
|
if email_current_user:
|
2014-07-23 01:37:21 +02:00
|
|
|
all_tickets_reported_by_current_user = Ticket.objects.select_related('queue').filter(
|
2011-11-29 14:08:08 +01:00
|
|
|
submitter_email=email_current_user,
|
|
|
|
).order_by('status')
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
tickets_in_queues = Ticket.objects.filter(
|
2016-10-23 22:02:02 +02:00
|
|
|
queue__in=user_queues,
|
|
|
|
)
|
2016-10-21 17:14:12 +02:00
|
|
|
basic_ticket_stats = calc_basic_ticket_stats(tickets_in_queues)
|
2011-11-29 14:08:08 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
# The following query builds a grid of queues & ticket statuses,
|
|
|
|
# to be displayed to the user. EG:
|
|
|
|
# Open Resolved
|
|
|
|
# Queue 1 10 4
|
|
|
|
# Queue 2 4 12
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
queues = HelpdeskUser(request.user).get_queues().values_list('id', flat=True)
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2015-06-11 12:18:45 +02:00
|
|
|
from_clause = """FROM helpdesk_ticket t,
|
|
|
|
helpdesk_queue q"""
|
2016-03-01 22:53:33 +01:00
|
|
|
if queues:
|
|
|
|
where_clause = """WHERE q.id = t.queue_id AND
|
|
|
|
q.id IN (%s)""" % (",".join(("%d" % pk for pk in queues)))
|
|
|
|
else:
|
|
|
|
where_clause = """WHERE q.id = t.queue_id"""
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2020-06-02 01:14:55 +02:00
|
|
|
# get user assigned tickets page
|
|
|
|
paginator = Paginator(
|
|
|
|
tickets, tickets_per_page)
|
|
|
|
try:
|
|
|
|
tickets = paginator.page(user_tickets_page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
tickets = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
tickets = paginator.page(
|
|
|
|
paginator.num_pages)
|
|
|
|
|
|
|
|
# get user completed tickets page
|
|
|
|
paginator = Paginator(
|
|
|
|
tickets_closed_resolved, tickets_per_page)
|
|
|
|
try:
|
|
|
|
tickets_closed_resolved = paginator.page(
|
|
|
|
user_tickets_closed_resolved_page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
tickets_closed_resolved = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
tickets_closed_resolved = paginator.page(
|
|
|
|
paginator.num_pages)
|
|
|
|
|
|
|
|
# get user submitted tickets page
|
|
|
|
paginator = Paginator(
|
|
|
|
all_tickets_reported_by_current_user, tickets_per_page)
|
|
|
|
try:
|
|
|
|
all_tickets_reported_by_current_user = paginator.page(
|
|
|
|
all_tickets_reported_by_current_user_page)
|
|
|
|
except PageNotAnInteger:
|
|
|
|
all_tickets_reported_by_current_user = paginator.page(1)
|
|
|
|
except EmptyPage:
|
|
|
|
all_tickets_reported_by_current_user = paginator.page(
|
|
|
|
paginator.num_pages)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/dashboard.html', {
|
|
|
|
'user_tickets': tickets,
|
|
|
|
'user_tickets_closed_resolved': tickets_closed_resolved,
|
|
|
|
'unassigned_tickets': unassigned_tickets,
|
2020-01-27 19:45:15 +01:00
|
|
|
'kbitems': kbitems,
|
2016-10-21 17:14:12 +02:00
|
|
|
'all_tickets_reported_by_current_user': all_tickets_reported_by_current_user,
|
|
|
|
'basic_ticket_stats': basic_ticket_stats,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
dashboard = staff_member_required(dashboard)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2019-10-13 01:05:00 +02:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
def ticket_perm_check(request, ticket):
|
|
|
|
huser = HelpdeskUser(request.user)
|
|
|
|
if not huser.can_access_queue(ticket.queue):
|
|
|
|
raise PermissionDenied()
|
|
|
|
if not huser.can_access_ticket(ticket):
|
|
|
|
raise PermissionDenied()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2019-10-13 01:05:00 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-01-15 05:00:19 +01:00
|
|
|
def delete_ticket(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-15 05:00:19 +01:00
|
|
|
if request.method == 'GET':
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/delete_ticket.html', {
|
|
|
|
'ticket': ticket,
|
|
|
|
})
|
2008-01-15 05:00:19 +01:00
|
|
|
else:
|
|
|
|
ticket.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:home'))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
delete_ticket = staff_member_required(delete_ticket)
|
2008-01-15 05:00:19 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2012-08-07 15:32:45 +02:00
|
|
|
def followup_edit(request, ticket_id, followup_id):
|
2016-10-21 17:14:12 +02:00
|
|
|
"""Edit followup options with an ability to change the ticket."""
|
2011-01-29 07:02:03 +01:00
|
|
|
followup = get_object_or_404(FollowUp, id=followup_id)
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2017-12-15 23:18:54 +01:00
|
|
|
|
2011-01-29 07:02:03 +01:00
|
|
|
if request.method == 'GET':
|
2016-10-21 17:14:12 +02:00
|
|
|
form = EditFollowUpForm(initial={
|
|
|
|
'title': escape(followup.title),
|
|
|
|
'ticket': followup.ticket,
|
|
|
|
'comment': escape(followup.comment),
|
|
|
|
'public': followup.public,
|
|
|
|
'new_status': followup.new_status,
|
2019-06-16 10:25:29 +02:00
|
|
|
'time_spent': format_time_spent(followup.time_spent),
|
2016-10-21 17:14:12 +02:00
|
|
|
})
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
ticketcc_string, show_subscribe = \
|
|
|
|
return_ticketccstring_and_show_subscribe(request.user, ticket)
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/followup_edit.html', {
|
|
|
|
'followup': followup,
|
|
|
|
'ticket': ticket,
|
|
|
|
'form': form,
|
|
|
|
'ticketcc_string': ticketcc_string,
|
2016-06-21 07:18:06 +02:00
|
|
|
})
|
2011-01-29 07:02:03 +01:00
|
|
|
elif request.method == 'POST':
|
|
|
|
form = EditFollowUpForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
title = form.cleaned_data['title']
|
|
|
|
_ticket = form.cleaned_data['ticket']
|
|
|
|
comment = form.cleaned_data['comment']
|
|
|
|
public = form.cleaned_data['public']
|
|
|
|
new_status = form.cleaned_data['new_status']
|
2019-02-06 14:24:43 +01:00
|
|
|
time_spent = form.cleaned_data['time_spent']
|
2016-10-21 17:14:12 +02:00
|
|
|
# will save previous date
|
2011-01-29 07:02:03 +01:00
|
|
|
old_date = followup.date
|
2019-02-06 14:24:43 +01:00
|
|
|
new_followup = FollowUp(title=title, date=old_date, ticket=_ticket,
|
|
|
|
comment=comment, public=public,
|
|
|
|
new_status=new_status,
|
|
|
|
time_spent=time_spent)
|
2011-11-19 09:34:07 +01:00
|
|
|
# keep old user if one did exist before.
|
|
|
|
if followup.user:
|
|
|
|
new_followup.user = followup.user
|
2011-01-29 07:02:03 +01:00
|
|
|
new_followup.save()
|
2011-11-19 09:34:07 +01:00
|
|
|
# get list of old attachments & link them to new_followup
|
2019-03-29 15:17:10 +01:00
|
|
|
attachments = FollowUpAttachment.objects.filter(followup=followup)
|
2011-11-19 09:34:07 +01:00
|
|
|
for attachment in attachments:
|
|
|
|
attachment.followup = new_followup
|
|
|
|
attachment.save()
|
|
|
|
# delete old followup
|
2012-08-07 15:32:45 +02:00
|
|
|
followup.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket.id]))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2012-08-07 15:43:26 +02:00
|
|
|
followup_edit = staff_member_required(followup_edit)
|
2012-08-07 15:32:45 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2012-08-07 15:32:45 +02:00
|
|
|
def followup_delete(request, ticket_id, followup_id):
|
2016-10-21 17:14:12 +02:00
|
|
|
"""followup delete for superuser"""
|
2012-08-07 15:32:45 +02:00
|
|
|
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
|
|
|
if not request.user.is_superuser:
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket.id]))
|
2012-08-07 15:32:45 +02:00
|
|
|
|
|
|
|
followup = get_object_or_404(FollowUp, id=followup_id)
|
|
|
|
followup.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket.id]))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2012-08-07 15:43:26 +02:00
|
|
|
followup_delete = staff_member_required(followup_delete)
|
2012-08-07 15:32:45 +02:00
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2007-12-27 01:29:17 +01:00
|
|
|
def view_ticket(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'take' in request.GET:
|
2008-08-19 10:50:38 +02:00
|
|
|
# Allow the user to assign the ticket to themselves whilst viewing it.
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2011-09-05 20:40:53 +02:00
|
|
|
# Trick the update_ticket() view into thinking it's being called with
|
|
|
|
# a valid POST.
|
|
|
|
request.POST = {
|
|
|
|
'owner': request.user.id,
|
|
|
|
'public': 1,
|
|
|
|
'title': ticket.title,
|
|
|
|
'comment': ''
|
|
|
|
}
|
|
|
|
return update_ticket(request, ticket_id)
|
2008-01-15 01:20:00 +01:00
|
|
|
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'subscribe' in request.GET:
|
2012-08-07 15:41:43 +02:00
|
|
|
# Allow the user to subscribe him/herself to the ticket whilst viewing it.
|
2016-10-21 17:14:12 +02:00
|
|
|
ticket_cc, show_subscribe = \
|
|
|
|
return_ticketccstring_and_show_subscribe(request.user, ticket)
|
|
|
|
if show_subscribe:
|
2012-08-07 15:41:43 +02:00
|
|
|
subscribe_staff_member_to_ticket(ticket, request.user)
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket.id]))
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
|
2008-08-19 10:50:38 +02:00
|
|
|
if not ticket.assigned_to:
|
2008-01-07 21:22:13 +01:00
|
|
|
owner = 0
|
|
|
|
else:
|
|
|
|
owner = ticket.assigned_to.id
|
2008-08-19 10:50:38 +02:00
|
|
|
|
|
|
|
# Trick the update_ticket() view into thinking it's being called with
|
|
|
|
# a valid POST.
|
|
|
|
request.POST = {
|
|
|
|
'new_status': Ticket.CLOSED_STATUS,
|
|
|
|
'public': 1,
|
|
|
|
'owner': owner,
|
|
|
|
'title': ticket.title,
|
|
|
|
'comment': _('Accepted resolution and closed ticket'),
|
2016-10-23 22:02:02 +02:00
|
|
|
}
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-07 21:22:13 +01:00
|
|
|
return update_ticket(request, ticket_id)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2012-01-17 22:40:44 +01:00
|
|
|
if helpdesk_settings.HELPDESK_STAFF_ONLY_TICKET_OWNERS:
|
2014-07-15 23:02:31 +02:00
|
|
|
users = User.objects.filter(is_active=True, is_staff=True).order_by(User.USERNAME_FIELD)
|
2012-01-17 22:40:44 +01:00
|
|
|
else:
|
2014-07-15 23:02:31 +02:00
|
|
|
users = User.objects.filter(is_active=True).order_by(User.USERNAME_FIELD)
|
2012-01-17 22:40:44 +01:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
queues = HelpdeskUser(request.user).get_queues()
|
2019-02-05 14:38:41 +01:00
|
|
|
queue_choices = _get_queue_choices(queues)
|
2012-01-21 00:03:07 +01:00
|
|
|
# TODO: shouldn't this template get a form to begin with?
|
2019-02-05 14:38:41 +01:00
|
|
|
form = TicketForm(initial={'due_date': ticket.due_date},
|
|
|
|
queue_choices=queue_choices)
|
2016-10-21 17:14:12 +02:00
|
|
|
|
|
|
|
ticketcc_string, show_subscribe = \
|
|
|
|
return_ticketccstring_and_show_subscribe(request.user, ticket)
|
|
|
|
|
2018-08-20 01:08:45 +02:00
|
|
|
submitter_userprofile = ticket.get_submitter_userprofile()
|
|
|
|
if submitter_userprofile is not None:
|
|
|
|
content_type = ContentType.objects.get_for_model(submitter_userprofile)
|
|
|
|
submitter_userprofile_url = reverse(
|
|
|
|
'admin:{app}_{model}_change'.format(app=content_type.app_label, model=content_type.model),
|
|
|
|
kwargs={'object_id': submitter_userprofile.id}
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
submitter_userprofile_url = None
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket.html', {
|
|
|
|
'ticket': ticket,
|
2018-08-20 01:08:45 +02:00
|
|
|
'submitter_userprofile_url': submitter_userprofile_url,
|
2016-10-21 17:14:12 +02:00
|
|
|
'form': form,
|
|
|
|
'active_users': users,
|
|
|
|
'priorities': Ticket.PRIORITY_CHOICES,
|
|
|
|
'preset_replies': PreSetReply.objects.filter(
|
|
|
|
Q(queues=ticket.queue) | Q(queues__isnull=True)),
|
|
|
|
'ticketcc_string': ticketcc_string,
|
|
|
|
'SHOW_SUBSCRIBE': show_subscribe,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2012-08-07 15:41:43 +02:00
|
|
|
def return_ticketccstring_and_show_subscribe(user, ticket):
|
2016-10-21 17:14:12 +02:00
|
|
|
"""used in view_ticket() and followup_edit()"""
|
2014-07-21 09:12:27 +02:00
|
|
|
# create the ticketcc_string and check whether current user is already
|
2012-08-07 15:41:43 +02:00
|
|
|
# subscribed
|
2014-10-22 07:18:04 +02:00
|
|
|
username = user.get_username().upper()
|
2012-08-07 15:41:43 +02:00
|
|
|
useremail = user.email.upper()
|
|
|
|
strings_to_check = list()
|
|
|
|
strings_to_check.append(username)
|
|
|
|
strings_to_check.append(useremail)
|
|
|
|
|
|
|
|
ticketcc_string = ''
|
|
|
|
all_ticketcc = ticket.ticketcc_set.all()
|
|
|
|
counter_all_ticketcc = len(all_ticketcc) - 1
|
2016-10-21 17:14:12 +02:00
|
|
|
show_subscribe = True
|
2012-08-07 15:41:43 +02:00
|
|
|
for i, ticketcc in enumerate(all_ticketcc):
|
|
|
|
ticketcc_this_entry = str(ticketcc.display)
|
2016-10-21 17:14:12 +02:00
|
|
|
ticketcc_string += ticketcc_this_entry
|
2012-08-07 15:41:43 +02:00
|
|
|
if i < counter_all_ticketcc:
|
2016-10-21 17:14:12 +02:00
|
|
|
ticketcc_string += ', '
|
2012-08-07 15:41:43 +02:00
|
|
|
if strings_to_check.__contains__(ticketcc_this_entry.upper()):
|
2016-10-21 17:14:12 +02:00
|
|
|
show_subscribe = False
|
2012-08-07 15:41:43 +02:00
|
|
|
|
|
|
|
# check whether current user is a submitter or assigned to ticket
|
|
|
|
assignedto_username = str(ticket.assigned_to).upper()
|
|
|
|
strings_to_check = list()
|
2017-01-13 17:37:10 +01:00
|
|
|
if ticket.submitter_email is not None:
|
|
|
|
submitter_email = ticket.submitter_email.upper()
|
|
|
|
strings_to_check.append(submitter_email)
|
2012-08-07 15:41:43 +02:00
|
|
|
strings_to_check.append(assignedto_username)
|
|
|
|
if strings_to_check.__contains__(username) or strings_to_check.__contains__(useremail):
|
2016-10-21 17:14:12 +02:00
|
|
|
show_subscribe = False
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return ticketcc_string, show_subscribe
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-02-19 14:09:03 +01:00
|
|
|
def subscribe_to_ticket_updates(ticket, user=None, email=None, can_view=True, can_update=False):
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
if ticket is not None:
|
2016-02-19 15:25:14 +01:00
|
|
|
|
|
|
|
queryset = TicketCC.objects.filter(ticket=ticket, user=user, email=email)
|
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
# Don't create duplicate entries for subscribers
|
2016-02-19 15:25:14 +01:00
|
|
|
if queryset.count() > 0:
|
|
|
|
return queryset.first()
|
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
if user is None and len(email) < 5:
|
|
|
|
raise ValidationError(
|
2018-12-28 17:32:49 +01:00
|
|
|
_('When you add somebody on Cc, you must provide either a User or a valid email. Email: %s' % email)
|
|
|
|
)
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2018-12-28 16:53:28 +01:00
|
|
|
ticketcc = TicketCC(
|
|
|
|
ticket=ticket,
|
|
|
|
user=user,
|
|
|
|
email=email,
|
|
|
|
can_view=can_view,
|
|
|
|
can_update=can_update
|
|
|
|
)
|
|
|
|
ticketcc.save()
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2016-03-17 05:12:42 +01:00
|
|
|
return ticketcc
|
|
|
|
|
2016-02-07 18:56:30 +01:00
|
|
|
|
2020-10-08 22:07:49 +02:00
|
|
|
def subscribe_staff_member_to_ticket(ticket, user, email='', can_view=True, can_update=False):
|
2018-12-28 16:53:28 +01:00
|
|
|
"""used in view_ticket() and update_ticket()"""
|
2016-02-19 14:09:03 +01:00
|
|
|
return subscribe_to_ticket_updates(ticket=ticket, user=user, email=email, can_view=can_view, can_update=can_update)
|
2018-12-28 17:32:49 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
def update_ticket(request, ticket_id, public=False):
|
2019-05-22 22:36:46 +02:00
|
|
|
|
|
|
|
ticket = None
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
if not (public or (
|
2017-12-28 13:23:51 +01:00
|
|
|
request.user.is_authenticated and
|
2016-10-21 17:14:12 +02:00
|
|
|
request.user.is_active and (
|
2017-10-30 08:17:40 +01:00
|
|
|
is_helpdesk_staff(request.user) or
|
2016-10-21 17:14:12 +02:00
|
|
|
helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE))):
|
2009-07-22 10:19:46 +02:00
|
|
|
|
2019-05-22 22:36:46 +02:00
|
|
|
key = request.POST.get('key')
|
|
|
|
email = request.POST.get('mail')
|
|
|
|
|
|
|
|
if key and email:
|
|
|
|
ticket = Ticket.objects.get(
|
|
|
|
id=ticket_id,
|
|
|
|
submitter_email__iexact=email,
|
|
|
|
secret_key__iexact=key
|
|
|
|
)
|
|
|
|
|
|
|
|
if not ticket:
|
|
|
|
return HttpResponseRedirect(
|
|
|
|
'%s?next=%s' % (reverse('helpdesk:login'), request.path)
|
|
|
|
)
|
|
|
|
|
|
|
|
if not ticket:
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2018-07-03 06:20:51 +02:00
|
|
|
date_re = re.compile(
|
|
|
|
r'(?P<month>\d{1,2})/(?P<day>\d{1,2})/(?P<year>\d{4})$'
|
|
|
|
)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
comment = request.POST.get('comment', '')
|
|
|
|
new_status = int(request.POST.get('new_status', ticket.status))
|
|
|
|
title = request.POST.get('title', '')
|
|
|
|
public = request.POST.get('public', False)
|
2012-08-07 12:25:21 +02:00
|
|
|
owner = int(request.POST.get('owner', -1))
|
2008-01-10 01:28:45 +01:00
|
|
|
priority = int(request.POST.get('priority', ticket.priority))
|
2012-05-08 14:36:13 +02:00
|
|
|
due_date_year = int(request.POST.get('due_date_year', 0))
|
|
|
|
due_date_month = int(request.POST.get('due_date_month', 0))
|
|
|
|
due_date_day = int(request.POST.get('due_date_day', 0))
|
2019-02-06 14:24:43 +01:00
|
|
|
if request.POST.get("time_spent"):
|
|
|
|
(hours, minutes) = [int(f) for f in request.POST.get("time_spent").split(":")]
|
|
|
|
time_spent = timedelta(hours=hours, minutes=minutes)
|
|
|
|
else:
|
|
|
|
time_spent = None
|
2018-07-03 06:32:23 +02:00
|
|
|
# NOTE: jQuery's default for dates is mm/dd/yy
|
2018-07-03 06:20:51 +02:00
|
|
|
# very US-centric but for now that's the only format supported
|
|
|
|
# until we clean up code to internationalize a little more
|
2018-07-13 07:10:25 +02:00
|
|
|
due_date = request.POST.get('due_date', None) or None
|
2018-07-03 06:20:51 +02:00
|
|
|
|
|
|
|
if due_date is not None:
|
2018-07-03 06:32:23 +02:00
|
|
|
# based on Django code to parse dates:
|
2018-07-03 06:20:51 +02:00
|
|
|
# https://docs.djangoproject.com/en/2.0/_modules/django/utils/dateparse/
|
|
|
|
match = date_re.match(due_date)
|
|
|
|
if match:
|
|
|
|
kw = {k: int(v) for k, v in match.groupdict().items()}
|
|
|
|
due_date = date(**kw)
|
2012-04-11 09:48:39 +02:00
|
|
|
else:
|
2018-07-03 06:20:51 +02:00
|
|
|
# old way, probably deprecated?
|
|
|
|
if not (due_date_year and due_date_month and due_date_day):
|
2012-05-11 09:02:55 +02:00
|
|
|
due_date = ticket.due_date
|
|
|
|
else:
|
2018-07-03 06:20:51 +02:00
|
|
|
# NOTE: must be an easier way to create a new date than doing it this way?
|
|
|
|
if ticket.due_date:
|
|
|
|
due_date = ticket.due_date
|
|
|
|
else:
|
|
|
|
due_date = timezone.now()
|
|
|
|
due_date = due_date.replace(due_date_year, due_date_month, due_date_day)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2012-08-07 15:22:39 +02:00
|
|
|
no_changes = all([
|
|
|
|
not request.FILES,
|
|
|
|
not comment,
|
|
|
|
new_status == ticket.status,
|
|
|
|
title == ticket.title,
|
|
|
|
priority == int(ticket.priority),
|
|
|
|
due_date == ticket.due_date,
|
2016-10-21 17:14:12 +02:00
|
|
|
(owner == -1) or (not owner and not ticket.assigned_to) or
|
|
|
|
(owner and User.objects.get(id=owner) == ticket.assigned_to),
|
2012-08-07 15:22:39 +02:00
|
|
|
])
|
|
|
|
if no_changes:
|
|
|
|
return return_to_ticket(request.user, helpdesk_settings, ticket)
|
|
|
|
|
2008-08-29 11:11:02 +02:00
|
|
|
# We need to allow the 'ticket' and 'queue' contexts to be applied to the
|
|
|
|
# comment.
|
2009-07-22 10:19:46 +02:00
|
|
|
context = safe_template_context(ticket)
|
2016-11-21 03:12:19 +01:00
|
|
|
|
|
|
|
from django.template import engines
|
|
|
|
template_func = engines['django'].from_string
|
2017-04-16 09:24:39 +02:00
|
|
|
# this prevents system from trying to render any template tags
|
|
|
|
# broken into two stages to prevent changes from first replace being themselves
|
|
|
|
# changed by the second replace due to conflicting syntax
|
2017-04-16 10:44:16 +02:00
|
|
|
comment = comment.replace('{%', 'X-HELPDESK-COMMENT-VERBATIM').replace('%}', 'X-HELPDESK-COMMENT-ENDVERBATIM')
|
|
|
|
comment = comment.replace('X-HELPDESK-COMMENT-VERBATIM', '{% verbatim %}{%').replace('X-HELPDESK-COMMENT-ENDVERBATIM', '%}{% endverbatim %}')
|
2017-04-16 09:24:39 +02:00
|
|
|
# render the neutralized template
|
2015-12-10 13:36:24 +01:00
|
|
|
comment = template_func(comment).render(context)
|
2008-08-29 11:11:02 +02:00
|
|
|
|
2019-12-17 14:41:30 +01:00
|
|
|
if owner == -1 and ticket.assigned_to:
|
2007-12-27 01:29:17 +01:00
|
|
|
owner = ticket.assigned_to.id
|
|
|
|
|
2019-02-06 14:24:43 +01:00
|
|
|
f = FollowUp(ticket=ticket, date=timezone.now(), comment=comment,
|
|
|
|
time_spent=time_spent)
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2014-07-30 06:58:57 +02:00
|
|
|
if is_helpdesk_staff(request.user):
|
2009-01-23 11:35:14 +01:00
|
|
|
f.user = request.user
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
f.public = public
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-01-21 02:02:12 +01:00
|
|
|
reassigned = False
|
|
|
|
|
2016-09-27 23:29:59 +02:00
|
|
|
old_owner = ticket.assigned_to
|
2019-12-17 14:41:30 +01:00
|
|
|
if owner != -1:
|
2008-11-09 06:34:51 +01:00
|
|
|
if owner != 0 and ((ticket.assigned_to and owner != ticket.assigned_to.id) or not ticket.assigned_to):
|
2007-12-27 01:29:17 +01:00
|
|
|
new_user = User.objects.get(id=owner)
|
2008-08-19 10:50:38 +02:00
|
|
|
f.title = _('Assigned to %(username)s') % {
|
2014-10-22 07:18:04 +02:00
|
|
|
'username': new_user.get_username(),
|
2016-10-23 22:02:02 +02:00
|
|
|
}
|
2007-12-27 01:29:17 +01:00
|
|
|
ticket.assigned_to = new_user
|
2008-01-21 02:02:12 +01:00
|
|
|
reassigned = True
|
2011-11-28 14:49:37 +01:00
|
|
|
# user changed owner to 'unassign'
|
|
|
|
elif owner == 0 and ticket.assigned_to is not None:
|
|
|
|
f.title = _('Unassigned')
|
|
|
|
ticket.assigned_to = None
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-09-27 23:29:59 +02:00
|
|
|
old_status_str = ticket.get_status_display()
|
|
|
|
old_status = ticket.status
|
2007-12-27 01:29:17 +01:00
|
|
|
if new_status != ticket.status:
|
|
|
|
ticket.status = new_status
|
|
|
|
ticket.save()
|
|
|
|
f.new_status = new_status
|
2016-09-27 23:29:59 +02:00
|
|
|
ticket_status_changed = True
|
2007-12-27 01:29:17 +01:00
|
|
|
if f.title:
|
|
|
|
f.title += ' and %s' % ticket.get_status_display()
|
|
|
|
else:
|
|
|
|
f.title = '%s' % ticket.get_status_display()
|
|
|
|
|
|
|
|
if not f.title:
|
|
|
|
if f.comment:
|
2008-05-07 11:04:18 +02:00
|
|
|
f.title = _('Comment')
|
2007-12-27 01:29:17 +01:00
|
|
|
else:
|
2008-05-07 11:04:18 +02:00
|
|
|
f.title = _('Updated')
|
2007-12-27 01:29:17 +01:00
|
|
|
|
|
|
|
f.save()
|
2018-07-19 06:06:57 +02:00
|
|
|
|
2009-01-20 09:12:05 +01:00
|
|
|
files = []
|
|
|
|
if request.FILES:
|
2017-10-30 08:17:40 +01:00
|
|
|
files = process_attachments(f, request.FILES.getlist('attachment'))
|
2009-01-20 09:12:05 +01:00
|
|
|
|
2016-03-08 20:09:48 +01:00
|
|
|
if title and title != ticket.title:
|
2008-08-19 10:50:38 +02:00
|
|
|
c = TicketChange(
|
|
|
|
followup=f,
|
|
|
|
field=_('Title'),
|
|
|
|
old_value=ticket.title,
|
|
|
|
new_value=title,
|
2016-10-23 22:02:02 +02:00
|
|
|
)
|
2007-12-27 01:29:17 +01:00
|
|
|
c.save()
|
|
|
|
ticket.title = title
|
|
|
|
|
2016-09-27 23:29:59 +02:00
|
|
|
if new_status != old_status:
|
|
|
|
c = TicketChange(
|
|
|
|
followup=f,
|
|
|
|
field=_('Status'),
|
|
|
|
old_value=old_status_str,
|
|
|
|
new_value=ticket.get_status_display(),
|
2016-10-29 10:08:57 +02:00
|
|
|
)
|
2016-09-27 23:29:59 +02:00
|
|
|
c.save()
|
|
|
|
|
|
|
|
if ticket.assigned_to != old_owner:
|
|
|
|
c = TicketChange(
|
|
|
|
followup=f,
|
|
|
|
field=_('Owner'),
|
|
|
|
old_value=old_owner,
|
|
|
|
new_value=ticket.assigned_to,
|
2016-10-29 10:08:57 +02:00
|
|
|
)
|
2016-09-27 23:29:59 +02:00
|
|
|
c.save()
|
|
|
|
|
2008-01-10 01:28:45 +01:00
|
|
|
if priority != ticket.priority:
|
2008-08-19 10:50:38 +02:00
|
|
|
c = TicketChange(
|
|
|
|
followup=f,
|
|
|
|
field=_('Priority'),
|
|
|
|
old_value=ticket.priority,
|
|
|
|
new_value=priority,
|
2016-10-23 22:02:02 +02:00
|
|
|
)
|
2008-01-10 01:28:45 +01:00
|
|
|
c.save()
|
|
|
|
ticket.priority = priority
|
|
|
|
|
2012-01-21 00:03:07 +01:00
|
|
|
if due_date != ticket.due_date:
|
|
|
|
c = TicketChange(
|
|
|
|
followup=f,
|
|
|
|
field=_('Due on'),
|
|
|
|
old_value=ticket.due_date,
|
|
|
|
new_value=due_date,
|
2016-10-23 22:02:02 +02:00
|
|
|
)
|
2012-01-21 00:03:07 +01:00
|
|
|
c.save()
|
|
|
|
ticket.due_date = due_date
|
|
|
|
|
2016-10-23 22:02:02 +02:00
|
|
|
if new_status in (Ticket.RESOLVED_STATUS, Ticket.CLOSED_STATUS):
|
2012-08-07 12:25:21 +02:00
|
|
|
if new_status == Ticket.RESOLVED_STATUS or ticket.resolution is None:
|
|
|
|
ticket.resolution = comment
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-21 09:12:27 +02:00
|
|
|
# ticket might have changed above, so we re-instantiate context with the
|
2011-02-08 22:19:17 +01:00
|
|
|
# (possibly) updated ticket.
|
|
|
|
context = safe_template_context(ticket)
|
2009-08-18 14:12:35 +02:00
|
|
|
context.update(
|
|
|
|
resolution=ticket.resolution,
|
|
|
|
comment=f.comment,
|
2016-10-23 22:02:02 +02:00
|
|
|
)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
messages_sent_to = set()
|
|
|
|
try:
|
|
|
|
messages_sent_to.add(request.user.email)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2016-10-21 17:14:12 +02:00
|
|
|
if public and (f.comment or (
|
2016-10-23 22:02:02 +02:00
|
|
|
f.new_status in (Ticket.RESOLVED_STATUS,
|
|
|
|
Ticket.CLOSED_STATUS))):
|
2008-01-07 21:22:13 +01:00
|
|
|
if f.new_status == Ticket.RESOLVED_STATUS:
|
2013-04-19 08:54:24 +02:00
|
|
|
template = 'resolved_'
|
2008-01-21 02:02:12 +01:00
|
|
|
elif f.new_status == Ticket.CLOSED_STATUS:
|
2013-04-19 08:54:24 +02:00
|
|
|
template = 'closed_'
|
2008-01-07 21:22:13 +01:00
|
|
|
else:
|
2013-04-19 08:54:24 +02:00
|
|
|
template = 'updated_'
|
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
roles = {
|
|
|
|
'submitter': (template + 'submitter', context),
|
|
|
|
'ticket_cc': (template + 'cc', context),
|
|
|
|
}
|
2018-11-01 19:30:34 +01:00
|
|
|
if ticket.assigned_to and ticket.assigned_to.usersettings_helpdesk.email_on_ticket_change:
|
|
|
|
roles['assigned_to'] = (template + 'cc', context)
|
2018-10-31 16:24:57 +01:00
|
|
|
messages_sent_to.update(ticket.send(roles, dont_send_to=messages_sent_to, fail_silently=True, files=files,))
|
|
|
|
|
|
|
|
if reassigned:
|
|
|
|
template_staff = 'assigned_owner'
|
|
|
|
elif f.new_status == Ticket.RESOLVED_STATUS:
|
|
|
|
template_staff = 'resolved_owner'
|
|
|
|
elif f.new_status == Ticket.CLOSED_STATUS:
|
|
|
|
template_staff = 'closed_owner'
|
|
|
|
else:
|
|
|
|
template_staff = 'updated_owner'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2018-11-01 19:30:34 +01:00
|
|
|
if ticket.assigned_to and (ticket.assigned_to.usersettings_helpdesk.email_on_ticket_change or (reassigned and ticket.assigned_to.usersettings_helpdesk.email_on_ticket_assigned)):
|
|
|
|
messages_sent_to.update(ticket.send(
|
|
|
|
{'assigned_to': (template_staff, context)},
|
|
|
|
dont_send_to=messages_sent_to,
|
2008-08-19 10:50:38 +02:00
|
|
|
fail_silently=True,
|
2009-01-20 09:12:05 +01:00
|
|
|
files=files,
|
2018-11-01 19:30:34 +01:00
|
|
|
))
|
2018-10-31 16:24:57 +01:00
|
|
|
|
|
|
|
if reassigned:
|
|
|
|
template_cc = 'assigned_cc'
|
|
|
|
elif f.new_status == Ticket.RESOLVED_STATUS:
|
|
|
|
template_cc = 'resolved_cc'
|
|
|
|
elif f.new_status == Ticket.CLOSED_STATUS:
|
|
|
|
template_cc = 'closed_cc'
|
|
|
|
else:
|
|
|
|
template_cc = 'updated_cc'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
messages_sent_to.update(ticket.send(
|
|
|
|
{'ticket_cc': (template_cc, context)},
|
|
|
|
dont_send_to=messages_sent_to,
|
|
|
|
fail_silently=True,
|
|
|
|
files=files,
|
|
|
|
))
|
2008-02-08 01:19:58 +01:00
|
|
|
|
2007-12-27 01:29:17 +01:00
|
|
|
ticket.save()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2012-08-07 15:41:43 +02:00
|
|
|
# auto subscribe user if enabled
|
2017-12-28 13:23:51 +01:00
|
|
|
if helpdesk_settings.HELPDESK_AUTO_SUBSCRIBE_ON_TICKET_RESPONSE and request.user.is_authenticated:
|
2012-08-07 15:41:43 +02:00
|
|
|
ticketcc_string, SHOW_SUBSCRIBE = return_ticketccstring_and_show_subscribe(request.user, ticket)
|
|
|
|
if SHOW_SUBSCRIBE:
|
|
|
|
subscribe_staff_member_to_ticket(ticket, request.user)
|
|
|
|
|
2012-08-07 15:22:39 +02:00
|
|
|
return return_to_ticket(request.user, helpdesk_settings, ticket)
|
|
|
|
|
2012-08-07 15:41:43 +02:00
|
|
|
|
2012-08-07 15:22:39 +02:00
|
|
|
def return_to_ticket(user, helpdesk_settings, ticket):
|
2016-10-21 17:14:12 +02:00
|
|
|
"""Helper function for update_ticket"""
|
2012-08-07 15:22:39 +02:00
|
|
|
|
2014-07-30 06:58:57 +02:00
|
|
|
if is_helpdesk_staff(user):
|
2009-01-23 11:35:14 +01:00
|
|
|
return HttpResponseRedirect(ticket.get_absolute_url())
|
|
|
|
else:
|
|
|
|
return HttpResponseRedirect(ticket.ticket_url)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2009-03-08 07:03:55 +01:00
|
|
|
def mass_update(request):
|
|
|
|
tickets = request.POST.getlist('ticket_id')
|
|
|
|
action = request.POST.get('action', None)
|
|
|
|
if not (tickets and action):
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2009-03-08 07:03:55 +01:00
|
|
|
|
|
|
|
if action.startswith('assign_'):
|
|
|
|
parts = action.split('_')
|
|
|
|
user = User.objects.get(id=parts[1])
|
|
|
|
action = 'assign'
|
2020-01-27 19:45:15 +01:00
|
|
|
if action == 'kbitem_none':
|
|
|
|
kbitem = None
|
|
|
|
action = 'set_kbitem'
|
|
|
|
if action.startswith('kbitem_'):
|
|
|
|
parts = action.split('_')
|
|
|
|
kbitem = KBItem.objects.get(id=parts[1])
|
|
|
|
action = 'set_kbitem'
|
2009-03-08 07:03:55 +01:00
|
|
|
elif action == 'take':
|
|
|
|
user = request.user
|
|
|
|
action = 'assign'
|
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
huser = HelpdeskUser(request.user)
|
2009-03-08 07:03:55 +01:00
|
|
|
for t in Ticket.objects.filter(id__in=tickets):
|
2019-10-11 17:12:39 +02:00
|
|
|
if not huser.can_access_queue(t.queue):
|
2015-12-16 17:51:15 +01:00
|
|
|
continue
|
|
|
|
|
2009-03-08 07:03:55 +01:00
|
|
|
if action == 'assign' and t.assigned_to != user:
|
|
|
|
t.assigned_to = user
|
|
|
|
t.save()
|
2016-10-21 17:14:12 +02:00
|
|
|
f = FollowUp(ticket=t,
|
|
|
|
date=timezone.now(),
|
|
|
|
title=_('Assigned to %(username)s in bulk update' % {
|
|
|
|
'username': user.get_username()
|
|
|
|
}),
|
|
|
|
public=True,
|
|
|
|
user=request.user)
|
2009-03-08 07:03:55 +01:00
|
|
|
f.save()
|
|
|
|
elif action == 'unassign' and t.assigned_to is not None:
|
|
|
|
t.assigned_to = None
|
|
|
|
t.save()
|
2016-10-21 17:14:12 +02:00
|
|
|
f = FollowUp(ticket=t,
|
|
|
|
date=timezone.now(),
|
|
|
|
title=_('Unassigned in bulk update'),
|
|
|
|
public=True,
|
|
|
|
user=request.user)
|
2009-03-08 07:03:55 +01:00
|
|
|
f.save()
|
2020-01-27 19:45:15 +01:00
|
|
|
elif action == 'set_kbitem':
|
|
|
|
t.kbitem = kbitem
|
|
|
|
t.save()
|
|
|
|
f = FollowUp(ticket=t,
|
|
|
|
date=timezone.now(),
|
|
|
|
title=_('KBItem set in bulk update'),
|
|
|
|
public=False,
|
|
|
|
user=request.user)
|
|
|
|
f.save()
|
2009-03-08 07:03:55 +01:00
|
|
|
elif action == 'close' and t.status != Ticket.CLOSED_STATUS:
|
|
|
|
t.status = Ticket.CLOSED_STATUS
|
|
|
|
t.save()
|
2016-10-21 17:14:12 +02:00
|
|
|
f = FollowUp(ticket=t,
|
|
|
|
date=timezone.now(),
|
|
|
|
title=_('Closed in bulk update'),
|
|
|
|
public=False,
|
|
|
|
user=request.user,
|
|
|
|
new_status=Ticket.CLOSED_STATUS)
|
2009-03-08 07:03:55 +01:00
|
|
|
f.save()
|
|
|
|
elif action == 'close_public' and t.status != Ticket.CLOSED_STATUS:
|
|
|
|
t.status = Ticket.CLOSED_STATUS
|
|
|
|
t.save()
|
2016-10-21 17:14:12 +02:00
|
|
|
f = FollowUp(ticket=t,
|
|
|
|
date=timezone.now(),
|
|
|
|
title=_('Closed in bulk update'),
|
|
|
|
public=True,
|
|
|
|
user=request.user,
|
|
|
|
new_status=Ticket.CLOSED_STATUS)
|
2009-03-08 07:03:55 +01:00
|
|
|
f.save()
|
|
|
|
# Send email to Submitter, Owner, Queue CC
|
2011-11-19 09:34:07 +01:00
|
|
|
context = safe_template_context(t)
|
2016-10-21 17:14:12 +02:00
|
|
|
context.update(resolution=t.resolution,
|
2017-08-21 01:26:45 +02:00
|
|
|
queue=queue_template_context(t.queue))
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
messages_sent_to = set()
|
|
|
|
try:
|
|
|
|
messages_sent_to.add(request.user.email)
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
|
|
|
|
2018-11-01 19:30:34 +01:00
|
|
|
roles = {
|
|
|
|
'submitter': ('closed_submitter', context),
|
|
|
|
'ticket_cc': ('closed_cc', context),
|
|
|
|
}
|
2020-10-08 22:07:49 +02:00
|
|
|
if t.assigned_to and t.assigned_to.usersettings_helpdesk.email_on_ticket_change:
|
2018-11-01 19:30:34 +01:00
|
|
|
roles['assigned_to'] = ('closed_owner', context),
|
|
|
|
|
2018-10-31 16:24:57 +01:00
|
|
|
messages_sent_to.update(t.send(
|
2018-11-01 19:30:34 +01:00
|
|
|
roles,
|
2018-10-31 16:24:57 +01:00
|
|
|
dont_send_to=messages_sent_to,
|
|
|
|
fail_silently=True,
|
|
|
|
))
|
2009-03-08 07:03:55 +01:00
|
|
|
|
|
|
|
elif action == 'delete':
|
|
|
|
t.delete()
|
|
|
|
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-03-08 07:03:55 +01:00
|
|
|
mass_update = staff_member_required(mass_update)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2007-12-27 01:29:17 +01:00
|
|
|
def ticket_list(request):
|
|
|
|
context = {}
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
huser = HelpdeskUser(request.user)
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2012-05-11 17:15:46 +02:00
|
|
|
# Query_params will hold a dictionary of parameters relating to
|
2008-08-28 11:06:24 +02:00
|
|
|
# a query, to be saved if needed:
|
|
|
|
query_params = {
|
|
|
|
'filtering': {},
|
2020-02-03 14:06:45 +01:00
|
|
|
'filtering_or': {},
|
2008-08-28 11:06:24 +02:00
|
|
|
'sorting': None,
|
2008-10-25 00:52:34 +02:00
|
|
|
'sortreverse': False,
|
2019-10-11 12:41:06 +02:00
|
|
|
'search_string': '',
|
2016-10-23 22:02:02 +02:00
|
|
|
}
|
2019-10-08 15:35:07 +02:00
|
|
|
default_query_params = {
|
2020-01-08 18:39:41 +01:00
|
|
|
'filtering': {
|
2020-01-27 17:56:49 +01:00
|
|
|
'status__in': [1, 2],
|
2020-01-08 18:39:41 +01:00
|
|
|
},
|
2019-10-08 15:35:07 +02:00
|
|
|
'sorting': 'created',
|
2019-10-11 12:41:06 +02:00
|
|
|
'search_string': '',
|
|
|
|
'sortreverse': False,
|
2019-10-08 15:35:07 +02:00
|
|
|
}
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2009-03-08 06:55:35 +01:00
|
|
|
# If the user is coming from the header/navigation search box, lets' first
|
|
|
|
# look at their query to see if they have entered a valid ticket number. If
|
|
|
|
# they have, just redirect to that ticket number. Otherwise, we treat it as
|
|
|
|
# a keyword search.
|
|
|
|
|
|
|
|
if request.GET.get('search_type', None) == 'header':
|
|
|
|
query = request.GET.get('q')
|
|
|
|
filter = None
|
|
|
|
if query.find('-') > 0:
|
|
|
|
try:
|
2016-06-26 02:45:55 +02:00
|
|
|
queue, id = Ticket.queue_and_id_from_query(query)
|
2009-03-08 06:55:35 +01:00
|
|
|
id = int(id)
|
|
|
|
except ValueError:
|
|
|
|
id = None
|
|
|
|
|
|
|
|
if id:
|
2016-10-21 17:14:12 +02:00
|
|
|
filter = {'queue__slug': queue, 'id': id}
|
2009-03-08 06:55:35 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
query = int(query)
|
|
|
|
except ValueError:
|
|
|
|
query = None
|
|
|
|
|
|
|
|
if query:
|
2016-10-21 17:14:12 +02:00
|
|
|
filter = {'id': int(query)}
|
2009-03-08 06:55:35 +01:00
|
|
|
|
|
|
|
if filter:
|
|
|
|
try:
|
2020-01-04 08:50:02 +01:00
|
|
|
ticket = huser.get_tickets_in_queues().get(**filter)
|
2009-03-08 06:55:35 +01:00
|
|
|
return HttpResponseRedirect(ticket.staff_url)
|
|
|
|
except Ticket.DoesNotExist:
|
|
|
|
# Go on to standard keyword searching
|
|
|
|
pass
|
|
|
|
|
2019-10-11 12:41:06 +02:00
|
|
|
try:
|
|
|
|
saved_query, query_params = load_saved_query(request, query_params)
|
|
|
|
except QueryLoadError:
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2016-06-28 18:04:39 +02:00
|
|
|
|
2019-10-11 12:41:06 +02:00
|
|
|
if saved_query:
|
|
|
|
pass
|
2020-01-08 18:39:41 +01:00
|
|
|
elif not {'queue', 'assigned_to', 'status', 'q', 'sort', 'sortreverse', 'kbitem'}.intersection(request.GET):
|
2019-10-08 15:35:07 +02:00
|
|
|
# Fall-back if no querying is being done
|
2019-06-16 10:25:29 +02:00
|
|
|
all_queues = Queue.objects.all()
|
2019-10-08 15:35:07 +02:00
|
|
|
query_params = deepcopy(default_query_params)
|
2008-08-28 11:06:24 +02:00
|
|
|
else:
|
2019-10-08 15:35:07 +02:00
|
|
|
filter_in_params = [
|
|
|
|
('queue', 'queue__id__in'),
|
|
|
|
('assigned_to', 'assigned_to__id__in'),
|
|
|
|
('status', 'status__in'),
|
2020-01-08 18:39:41 +01:00
|
|
|
('kbitem', 'kbitem__in'),
|
2019-10-08 15:35:07 +02:00
|
|
|
]
|
2020-02-03 14:06:45 +01:00
|
|
|
filter_null_params = dict([
|
|
|
|
('queue', 'queue__id__isnull'),
|
|
|
|
('assigned_to', 'assigned_to__id__isnull'),
|
|
|
|
('status', 'status__isnull'),
|
|
|
|
('kbitem', 'kbitem__isnull'),
|
|
|
|
])
|
2019-10-08 15:35:07 +02:00
|
|
|
for param, filter_command in filter_in_params:
|
2020-02-03 14:06:45 +01:00
|
|
|
if not request.GET.get(param) is None:
|
|
|
|
patterns = request.GET.getlist(param)
|
2019-10-08 15:35:07 +02:00
|
|
|
try:
|
|
|
|
pattern_pks = [int(pattern) for pattern in patterns]
|
2020-02-03 14:06:45 +01:00
|
|
|
if -1 in pattern_pks:
|
|
|
|
query_params['filtering_or'][filter_null_params[param]] = True
|
2020-02-11 16:44:18 +01:00
|
|
|
else:
|
|
|
|
query_params['filtering_or'][filter_command] = pattern_pks
|
2019-10-08 15:35:07 +02:00
|
|
|
query_params['filtering'][filter_command] = pattern_pks
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2008-08-28 11:06:24 +02:00
|
|
|
|
2011-05-13 00:02:59 +02:00
|
|
|
date_from = request.GET.get('date_from')
|
|
|
|
if date_from:
|
|
|
|
query_params['filtering']['created__gte'] = date_from
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2011-05-13 00:02:59 +02:00
|
|
|
date_to = request.GET.get('date_to')
|
|
|
|
if date_to:
|
|
|
|
query_params['filtering']['created__lte'] = date_to
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
# KEYWORD SEARCHING
|
2019-10-11 12:41:06 +02:00
|
|
|
q = request.GET.get('q', '')
|
|
|
|
context['query'] = q
|
|
|
|
query_params['search_string'] = q
|
2008-08-28 11:06:24 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
# SORTING
|
2008-08-28 11:06:24 +02:00
|
|
|
sort = request.GET.get('sort', None)
|
2020-01-08 18:39:41 +01:00
|
|
|
if sort not in ('status', 'assigned_to', 'created', 'title', 'queue', 'priority', 'kbitem'):
|
2008-08-28 11:06:24 +02:00
|
|
|
sort = 'created'
|
|
|
|
query_params['sorting'] = sort
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
sortreverse = request.GET.get('sortreverse', None)
|
|
|
|
query_params['sortreverse'] = sortreverse
|
2008-08-28 11:06:24 +02:00
|
|
|
|
2019-10-11 12:41:06 +02:00
|
|
|
urlsafe_query = query_to_base64(query_params)
|
|
|
|
|
2019-10-30 19:34:58 +01:00
|
|
|
Query(huser, base64query=urlsafe_query).refresh_query()
|
2019-10-11 12:41:06 +02:00
|
|
|
|
|
|
|
user_saved_queries = SavedSearch.objects.filter(Q(user=request.user) | Q(shared__exact=True))
|
2019-10-13 01:05:00 +02:00
|
|
|
|
2009-03-08 06:49:08 +01:00
|
|
|
search_message = ''
|
2019-10-11 12:41:06 +02:00
|
|
|
if query_params['search_string'] and settings.DATABASES['default']['ENGINE'].endswith('sqlite'):
|
2016-10-21 17:14:12 +02:00
|
|
|
search_message = _(
|
|
|
|
'<p><strong>Note:</strong> Your keyword search is case sensitive '
|
|
|
|
'because of your database. This means the search will <strong>not</strong> '
|
|
|
|
'be accurate. By switching to a different database system you will gain '
|
|
|
|
'better searching! For more information, read the '
|
|
|
|
'<a href="http://docs.djangoproject.com/en/dev/ref/databases/#sqlite-string-matching">'
|
|
|
|
'Django Documentation on string matching in SQLite</a>.')
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2020-02-11 17:11:41 +01:00
|
|
|
kbitem_choices = [(item.pk, str(item)) for item in KBItem.objects.all()]
|
2020-01-08 18:39:41 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket_list.html', dict(
|
|
|
|
context,
|
2018-10-05 14:54:22 +02:00
|
|
|
default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page,
|
2016-10-21 17:14:12 +02:00
|
|
|
user_choices=User.objects.filter(is_active=True, is_staff=True),
|
2020-01-27 19:45:15 +01:00
|
|
|
kb_items=KBItem.objects.all(),
|
2019-10-11 17:12:39 +02:00
|
|
|
queue_choices=huser.get_queues(),
|
2016-10-21 17:14:12 +02:00
|
|
|
status_choices=Ticket.STATUS_CHOICES,
|
2020-01-08 18:39:41 +01:00
|
|
|
kbitem_choices=kbitem_choices,
|
2016-10-21 17:14:12 +02:00
|
|
|
urlsafe_query=urlsafe_query,
|
|
|
|
user_saved_queries=user_saved_queries,
|
|
|
|
query_params=query_params,
|
2019-10-11 12:41:06 +02:00
|
|
|
from_saved_query=saved_query is not None,
|
2016-10-21 17:14:12 +02:00
|
|
|
saved_query=saved_query,
|
|
|
|
search_message=search_message,
|
|
|
|
))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
ticket_list = staff_member_required(ticket_list)
|
2007-12-27 01:29:17 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2019-10-11 12:41:06 +02:00
|
|
|
class QueryLoadError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def load_saved_query(request, query_params=None):
|
|
|
|
saved_query = None
|
|
|
|
|
|
|
|
if request.GET.get('saved_query', None):
|
|
|
|
try:
|
2020-10-08 22:07:49 +02:00
|
|
|
saved_query = SavedSearch.objects.get(
|
|
|
|
Q(pk=request.GET.get('saved_query')) & (Q(shared=True) | Q(user=request.user))
|
|
|
|
)
|
|
|
|
except (SavedSearch.DoesNotExist, ValueError):
|
2019-10-11 12:41:06 +02:00
|
|
|
raise QueryLoadError()
|
|
|
|
|
|
|
|
try:
|
|
|
|
# we get a string like: b'stuff'
|
|
|
|
# so leave of the first two chars (b') and last (')
|
2019-10-11 15:50:35 +02:00
|
|
|
if saved_query.query.startswith('b\''):
|
|
|
|
b64query = saved_query.query[2:-1]
|
|
|
|
else:
|
|
|
|
b64query = saved_query.query
|
2019-10-11 12:41:06 +02:00
|
|
|
query_params = query_from_base64(b64query)
|
|
|
|
except json.JSONDecodeError:
|
|
|
|
raise QueryLoadError()
|
|
|
|
return (saved_query, query_params)
|
|
|
|
|
|
|
|
|
2018-10-15 02:23:28 +02:00
|
|
|
@helpdesk_staff_member_required
|
2019-10-11 12:41:06 +02:00
|
|
|
@api_view(['GET'])
|
2019-10-11 15:50:35 +02:00
|
|
|
def datatables_ticket_list(request, query):
|
2018-10-15 02:23:28 +02:00
|
|
|
"""
|
|
|
|
Datatable on ticket_list.html uses this view from to get objects to display
|
2019-10-11 12:41:06 +02:00
|
|
|
on the table. query_tickets_by_args is at lib.py, DatatablesTicketSerializer is in
|
2018-10-15 02:23:28 +02:00
|
|
|
serializers.py. The serializers and this view use django-rest_framework methods
|
|
|
|
"""
|
2019-10-30 19:34:58 +01:00
|
|
|
query = Query(HelpdeskUser(request.user), base64query=query)
|
|
|
|
result = query.get_datatables_context(**request.query_params)
|
2019-10-11 15:50:35 +02:00
|
|
|
return (JsonResponse(result, status=status.HTTP_200_OK))
|
2019-10-21 19:21:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
@helpdesk_staff_member_required
|
|
|
|
@api_view(['GET'])
|
|
|
|
def timeline_ticket_list(request, query):
|
2019-10-30 19:34:58 +01:00
|
|
|
query = Query(HelpdeskUser(request.user), base64query=query)
|
|
|
|
return (JsonResponse(query.get_timeline_context(), status=status.HTTP_200_OK))
|
2018-10-15 02:23:28 +02:00
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2009-06-03 13:43:46 +02:00
|
|
|
def edit_ticket(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2015-12-16 16:09:15 +01:00
|
|
|
|
2009-06-03 13:43:46 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
form = EditTicketForm(request.POST, instance=ticket)
|
|
|
|
if form.is_valid():
|
|
|
|
ticket = form.save()
|
|
|
|
return HttpResponseRedirect(ticket.get_absolute_url())
|
|
|
|
else:
|
|
|
|
form = EditTicketForm(instance=ticket)
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2018-09-02 11:27:39 +02:00
|
|
|
return render(request, 'helpdesk/edit_ticket.html', {'form': form, 'ticket': ticket})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
edit_ticket = staff_member_required(edit_ticket)
|
2009-06-03 13:43:46 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2020-01-08 18:39:41 +01:00
|
|
|
class CreateTicketView(MustBeStaffMixin, abstract_views.AbstractCreateTicketMixin, FormView):
|
2018-09-07 19:05:16 +02:00
|
|
|
template_name = 'helpdesk/create_ticket.html'
|
|
|
|
form_class = TicketForm
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2018-09-07 19:05:16 +02:00
|
|
|
def get_initial(self):
|
2020-01-08 18:39:41 +01:00
|
|
|
initial_data = super().get_initial()
|
2018-09-07 19:05:16 +02:00
|
|
|
return initial_data
|
2009-08-06 10:56:02 +02:00
|
|
|
|
2019-02-05 14:38:41 +01:00
|
|
|
def get_form_kwargs(self):
|
|
|
|
kwargs = super().get_form_kwargs()
|
2019-10-11 17:12:39 +02:00
|
|
|
queues = HelpdeskUser(self.request.user).get_queues()
|
2019-02-05 14:38:41 +01:00
|
|
|
kwargs["queue_choices"] = _get_queue_choices(queues)
|
|
|
|
return kwargs
|
|
|
|
|
2018-09-07 19:05:16 +02:00
|
|
|
def form_valid(self, form):
|
2020-04-15 13:42:52 +02:00
|
|
|
self.ticket = form.save(user=self.request.user if self.request.user.is_authenticated else None)
|
2018-09-07 19:05:16 +02:00
|
|
|
return super().form_valid(form)
|
2017-12-06 08:06:07 +01:00
|
|
|
|
2018-09-07 19:05:16 +02:00
|
|
|
def get_success_url(self):
|
|
|
|
request = self.request
|
2019-10-11 17:12:39 +02:00
|
|
|
if HelpdeskUser(request.user).can_access_queue(self.ticket.queue):
|
2018-09-07 19:05:16 +02:00
|
|
|
return self.ticket.get_absolute_url()
|
|
|
|
else:
|
|
|
|
return reverse('helpdesk:dashboard')
|
2008-01-11 02:00:01 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-01-11 02:00:01 +01:00
|
|
|
def raw_details(request, type):
|
2008-08-19 10:50:38 +02:00
|
|
|
# TODO: This currently only supports spewing out 'PreSetReply' objects,
|
|
|
|
# in the future it needs to be expanded to include other items. All it
|
|
|
|
# does is return a plain-text representation of an object.
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
if type not in ('preset',):
|
2008-01-11 02:00:01 +01:00
|
|
|
raise Http404
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-11 02:00:01 +01:00
|
|
|
if type == 'preset' and request.GET.get('id', False):
|
|
|
|
try:
|
|
|
|
preset = PreSetReply.objects.get(id=request.GET.get('id'))
|
|
|
|
return HttpResponse(preset.body)
|
|
|
|
except PreSetReply.DoesNotExist:
|
|
|
|
raise Http404
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-11 02:00:01 +01:00
|
|
|
raise Http404
|
2008-01-16 01:26:24 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
raw_details = staff_member_required(raw_details)
|
2008-01-16 01:26:24 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-01-16 05:52:30 +01:00
|
|
|
def hold_ticket(request, ticket_id, unhold=False):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2008-01-16 05:52:30 +01:00
|
|
|
|
|
|
|
if unhold:
|
|
|
|
ticket.on_hold = False
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Ticket taken off hold')
|
2008-01-16 05:52:30 +01:00
|
|
|
else:
|
|
|
|
ticket.on_hold = True
|
2008-05-07 11:04:18 +02:00
|
|
|
title = _('Ticket placed on hold')
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 05:52:30 +01:00
|
|
|
f = FollowUp(
|
2016-10-21 17:14:12 +02:00
|
|
|
ticket=ticket,
|
|
|
|
user=request.user,
|
|
|
|
title=title,
|
|
|
|
date=timezone.now(),
|
|
|
|
public=True,
|
2008-01-16 05:52:30 +01:00
|
|
|
)
|
|
|
|
f.save()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 05:52:30 +01:00
|
|
|
ticket.save()
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-01-16 05:52:30 +01:00
|
|
|
return HttpResponseRedirect(ticket.get_absolute_url())
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
hold_ticket = staff_member_required(hold_ticket)
|
2008-01-16 05:52:30 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-01-16 05:52:30 +01:00
|
|
|
def unhold_ticket(request, ticket_id):
|
|
|
|
return hold_ticket(request, ticket_id, unhold=True)
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
unhold_ticket = staff_member_required(unhold_ticket)
|
2008-01-16 05:52:30 +01:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-02-08 06:29:51 +01:00
|
|
|
def rss_list(request):
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/rss_list.html', {'queues': Queue.objects.all()})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
rss_list = staff_member_required(rss_list)
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-04-02 01:26:12 +02:00
|
|
|
def report_index(request):
|
2009-12-23 12:47:50 +01:00
|
|
|
number_tickets = Ticket.objects.all().count()
|
2011-05-12 01:01:35 +02:00
|
|
|
saved_query = request.GET.get('saved_query', None)
|
2016-09-09 08:45:12 +02:00
|
|
|
|
2019-10-11 17:12:39 +02:00
|
|
|
user_queues = HelpdeskUser(request.user).get_queues()
|
2016-10-29 10:08:57 +02:00
|
|
|
Tickets = Ticket.objects.filter(queue__in=user_queues)
|
2016-09-09 08:45:12 +02:00
|
|
|
basic_ticket_stats = calc_basic_ticket_stats(Tickets)
|
|
|
|
|
|
|
|
# The following query builds a grid of queues & ticket statuses,
|
|
|
|
# to be displayed to the user. EG:
|
|
|
|
# Open Resolved
|
|
|
|
# Queue 1 10 4
|
|
|
|
# Queue 2 4 12
|
2018-03-26 14:46:07 +02:00
|
|
|
Queues = user_queues if user_queues else Queue.objects.all()
|
|
|
|
|
|
|
|
dash_tickets = []
|
|
|
|
for queue in Queues:
|
|
|
|
dash_ticket = {
|
|
|
|
'queue': queue.id,
|
|
|
|
'name': queue.title,
|
|
|
|
'open': queue.ticket_set.filter(status__in=[1, 2]).count(),
|
|
|
|
'resolved': queue.ticket_set.filter(status=3).count(),
|
|
|
|
'closed': queue.ticket_set.filter(status=4).count(),
|
2019-06-16 10:25:29 +02:00
|
|
|
'time_spent': format_time_spent(queue.time_spent),
|
|
|
|
'dedicated_time': format_time_spent(queue.dedicated_time)
|
2018-03-26 14:46:07 +02:00
|
|
|
}
|
|
|
|
dash_tickets.append(dash_ticket)
|
2016-09-09 08:45:12 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/report_index.html', {
|
|
|
|
'number_tickets': number_tickets,
|
|
|
|
'saved_query': saved_query,
|
2016-10-29 09:47:15 +02:00
|
|
|
'basic_ticket_stats': basic_ticket_stats,
|
|
|
|
'dash_tickets': dash_tickets,
|
2016-10-21 17:14:12 +02:00
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
report_index = staff_member_required(report_index)
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-04-02 01:26:12 +02:00
|
|
|
def run_report(request, report):
|
2016-10-21 17:14:12 +02:00
|
|
|
if Ticket.objects.all().count() == 0 or report not in (
|
|
|
|
'queuemonth', 'usermonth', 'queuestatus', 'queuepriority', 'userstatus',
|
|
|
|
'userpriority', 'userqueue', 'daysuntilticketclosedbymonth'):
|
2016-11-11 04:31:37 +01:00
|
|
|
return HttpResponseRedirect(reverse("helpdesk:report_index"))
|
2011-05-11 12:07:46 +02:00
|
|
|
|
2015-12-16 16:09:15 +01:00
|
|
|
report_queryset = Ticket.objects.all().select_related().filter(
|
2019-10-11 17:12:39 +02:00
|
|
|
queue__in=HelpdeskUser(request.user).get_queues()
|
2015-12-16 16:09:15 +01:00
|
|
|
)
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2019-10-11 12:41:06 +02:00
|
|
|
try:
|
|
|
|
saved_query, query_params = load_saved_query(request)
|
|
|
|
except QueryLoadError:
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk:report_index'))
|
2011-05-11 12:07:46 +02:00
|
|
|
|
|
|
|
if request.GET.get('saved_query', None):
|
2020-10-12 23:57:00 +02:00
|
|
|
Query(report_queryset, query_to_base64(query_params))
|
2011-05-11 12:07:46 +02:00
|
|
|
|
|
|
|
from collections import defaultdict
|
|
|
|
summarytable = defaultdict(int)
|
2012-08-07 15:51:52 +02:00
|
|
|
# a second table for more complex queries
|
|
|
|
summarytable2 = defaultdict(int)
|
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
first_ticket = Ticket.objects.all().order_by('created')[0]
|
|
|
|
first_month = first_ticket.created.month
|
|
|
|
first_year = first_ticket.created.year
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
last_ticket = Ticket.objects.all().order_by('-created')[0]
|
|
|
|
last_month = last_ticket.created.month
|
|
|
|
last_year = last_ticket.created.year
|
|
|
|
|
|
|
|
periods = []
|
|
|
|
year, month = first_year, first_month
|
|
|
|
working = True
|
2016-10-29 10:08:57 +02:00
|
|
|
periods.append("%s-%s" % (year, month))
|
2008-04-02 01:26:12 +02:00
|
|
|
|
|
|
|
while working:
|
|
|
|
month += 1
|
|
|
|
if month > 12:
|
|
|
|
year += 1
|
|
|
|
month = 1
|
2009-12-16 09:30:50 +01:00
|
|
|
if (year > last_year) or (month > last_month and year >= last_year):
|
2008-04-02 01:26:12 +02:00
|
|
|
working = False
|
2016-10-29 10:08:57 +02:00
|
|
|
periods.append("%s-%s" % (year, month))
|
2008-04-02 01:26:12 +02:00
|
|
|
|
|
|
|
if report == 'userpriority':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('User by Priority')
|
|
|
|
col1heading = _('User')
|
2015-06-04 08:04:14 +02:00
|
|
|
possible_options = [t[1].title() for t in Ticket.PRIORITY_CHOICES]
|
2011-05-11 12:07:46 +02:00
|
|
|
charttype = 'bar'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'userqueue':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('User by Queue')
|
|
|
|
col1heading = _('User')
|
2019-10-11 17:12:39 +02:00
|
|
|
queue_options = HelpdeskUser(request.user).get_queues()
|
2015-11-18 15:07:33 +01:00
|
|
|
possible_options = [q.title for q in queue_options]
|
2011-05-11 12:07:46 +02:00
|
|
|
charttype = 'bar'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'userstatus':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('User by Status')
|
|
|
|
col1heading = _('User')
|
2015-06-04 08:04:14 +02:00
|
|
|
possible_options = [s[1].title() for s in Ticket.STATUS_CHOICES]
|
2011-05-11 12:07:46 +02:00
|
|
|
charttype = 'bar'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'usermonth':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('User by Month')
|
|
|
|
col1heading = _('User')
|
|
|
|
possible_options = periods
|
|
|
|
charttype = 'date'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'queuepriority':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('Queue by Priority')
|
|
|
|
col1heading = _('Queue')
|
2015-06-04 08:04:14 +02:00
|
|
|
possible_options = [t[1].title() for t in Ticket.PRIORITY_CHOICES]
|
2011-05-11 12:07:46 +02:00
|
|
|
charttype = 'bar'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'queuestatus':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('Queue by Status')
|
|
|
|
col1heading = _('Queue')
|
2015-06-04 08:04:14 +02:00
|
|
|
possible_options = [s[1].title() for s in Ticket.STATUS_CHOICES]
|
2011-05-11 12:07:46 +02:00
|
|
|
charttype = 'bar'
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-04-02 01:26:12 +02:00
|
|
|
elif report == 'queuemonth':
|
2011-05-11 12:07:46 +02:00
|
|
|
title = _('Queue by Month')
|
|
|
|
col1heading = _('Queue')
|
|
|
|
possible_options = periods
|
|
|
|
charttype = 'date'
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
elif report == 'daysuntilticketclosedbymonth':
|
|
|
|
title = _('Days until ticket closed by Month')
|
|
|
|
col1heading = _('Queue')
|
|
|
|
possible_options = periods
|
|
|
|
charttype = 'date'
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
metric3 = False
|
2011-05-11 12:07:46 +02:00
|
|
|
for ticket in report_queryset:
|
|
|
|
if report == 'userpriority':
|
|
|
|
metric1 = u'%s' % ticket.get_assigned_to
|
|
|
|
metric2 = u'%s' % ticket.get_priority_display()
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2011-05-11 12:07:46 +02:00
|
|
|
elif report == 'userqueue':
|
|
|
|
metric1 = u'%s' % ticket.get_assigned_to
|
|
|
|
metric2 = u'%s' % ticket.queue.title
|
2008-04-02 01:26:12 +02:00
|
|
|
|
2011-05-11 12:07:46 +02:00
|
|
|
elif report == 'userstatus':
|
|
|
|
metric1 = u'%s' % ticket.get_assigned_to
|
|
|
|
metric2 = u'%s' % ticket.get_status_display()
|
|
|
|
|
|
|
|
elif report == 'usermonth':
|
|
|
|
metric1 = u'%s' % ticket.get_assigned_to
|
2016-09-09 08:45:12 +02:00
|
|
|
metric2 = u'%s-%s' % (ticket.created.year, ticket.created.month)
|
2011-05-11 12:07:46 +02:00
|
|
|
|
|
|
|
elif report == 'queuepriority':
|
|
|
|
metric1 = u'%s' % ticket.queue.title
|
|
|
|
metric2 = u'%s' % ticket.get_priority_display()
|
|
|
|
|
|
|
|
elif report == 'queuestatus':
|
|
|
|
metric1 = u'%s' % ticket.queue.title
|
|
|
|
metric2 = u'%s' % ticket.get_status_display()
|
|
|
|
|
|
|
|
elif report == 'queuemonth':
|
|
|
|
metric1 = u'%s' % ticket.queue.title
|
2016-09-09 08:45:12 +02:00
|
|
|
metric2 = u'%s-%s' % (ticket.created.year, ticket.created.month)
|
2011-05-11 12:07:46 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
elif report == 'daysuntilticketclosedbymonth':
|
|
|
|
metric1 = u'%s' % ticket.queue.title
|
2016-09-09 08:45:12 +02:00
|
|
|
metric2 = u'%s-%s' % (ticket.created.year, ticket.created.month)
|
2012-08-07 15:51:52 +02:00
|
|
|
metric3 = ticket.modified - ticket.created
|
|
|
|
metric3 = metric3.days
|
|
|
|
|
2011-05-11 12:07:46 +02:00
|
|
|
summarytable[metric1, metric2] += 1
|
2012-08-07 15:51:52 +02:00
|
|
|
if metric3:
|
|
|
|
if report == 'daysuntilticketclosedbymonth':
|
|
|
|
summarytable2[metric1, metric2] += metric3
|
|
|
|
|
2011-05-11 12:07:46 +02:00
|
|
|
table = []
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
if report == 'daysuntilticketclosedbymonth':
|
|
|
|
for key in summarytable2.keys():
|
|
|
|
summarytable[key] = summarytable2[key] / summarytable[key]
|
|
|
|
|
2015-11-18 15:07:33 +01:00
|
|
|
header1 = sorted(set(list(i for i, _ in summarytable.keys())))
|
2014-07-21 09:12:27 +02:00
|
|
|
|
2011-05-11 12:07:46 +02:00
|
|
|
column_headings = [col1heading] + possible_options
|
|
|
|
|
2020-10-05 10:20:03 +02:00
|
|
|
# Prepare a dict to store totals for each possible option
|
|
|
|
totals = {}
|
2011-05-11 12:07:46 +02:00
|
|
|
# Pivot the data so that 'header1' fields are always first column
|
|
|
|
# in the row, and 'possible_options' are always the 2nd - nth columns.
|
|
|
|
for item in header1:
|
|
|
|
data = []
|
|
|
|
for hdr in possible_options:
|
2020-10-05 10:20:03 +02:00
|
|
|
if hdr not in totals.keys():
|
|
|
|
totals[hdr] = summarytable[item, hdr]
|
|
|
|
else:
|
|
|
|
totals[hdr] += summarytable[item, hdr]
|
2011-05-11 12:07:46 +02:00
|
|
|
data.append(summarytable[item, hdr])
|
|
|
|
table.append([item] + data)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2016-09-09 08:45:12 +02:00
|
|
|
# Zip data and headers together in one list for Morris.js charts
|
|
|
|
# will get a list like [(Header1, Data1), (Header2, Data2)...]
|
|
|
|
seriesnum = 0
|
|
|
|
morrisjs_data = []
|
|
|
|
for label in column_headings[1:]:
|
|
|
|
seriesnum += 1
|
2016-10-29 10:08:57 +02:00
|
|
|
datadict = {"x": label}
|
|
|
|
for n in range(0, len(table)):
|
2016-09-09 08:45:12 +02:00
|
|
|
datadict[n] = table[n][seriesnum]
|
|
|
|
morrisjs_data.append(datadict)
|
|
|
|
|
|
|
|
series_names = []
|
|
|
|
for series in table:
|
|
|
|
series_names.append(series[0])
|
|
|
|
|
2020-10-05 10:20:03 +02:00
|
|
|
# Add total row to table
|
2020-10-08 00:48:03 +02:00
|
|
|
total_data = ['Total']
|
2020-10-05 10:20:03 +02:00
|
|
|
for hdr in possible_options:
|
|
|
|
total_data.append(str(totals[hdr]))
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/report_output.html', {
|
|
|
|
'title': title,
|
|
|
|
'charttype': charttype,
|
|
|
|
'data': table,
|
2020-10-08 00:48:03 +02:00
|
|
|
'total_data': total_data,
|
2016-10-21 17:14:12 +02:00
|
|
|
'headings': column_headings,
|
2016-10-29 09:47:15 +02:00
|
|
|
'series_names': series_names,
|
|
|
|
'morrisjs_data': morrisjs_data,
|
2019-10-11 12:41:06 +02:00
|
|
|
'from_saved_query': saved_query is not None,
|
2016-10-21 17:14:12 +02:00
|
|
|
'saved_query': saved_query,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
run_report = staff_member_required(run_report)
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-08-28 11:06:24 +02:00
|
|
|
def save_query(request):
|
|
|
|
title = request.POST.get('title', None)
|
|
|
|
shared = request.POST.get('shared', False)
|
2016-10-23 22:02:02 +02:00
|
|
|
if shared == 'on': # django only translates '1', 'true', 't' into True
|
2016-06-30 00:31:46 +02:00
|
|
|
shared = True
|
2008-08-28 11:06:24 +02:00
|
|
|
query_encoded = request.POST.get('query_encoded', None)
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
if not title or not query_encoded:
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2008-08-28 11:06:24 +02:00
|
|
|
query = SavedSearch(title=title, shared=shared, query=query_encoded, user=request.user)
|
|
|
|
query.save()
|
2009-03-08 07:03:55 +01:00
|
|
|
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect('%s?saved_query=%s' % (reverse('helpdesk:list'), query.id))
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
save_query = staff_member_required(save_query)
|
2008-08-28 11:06:24 +02:00
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2008-08-28 11:06:24 +02:00
|
|
|
def delete_saved_query(request, id):
|
|
|
|
query = get_object_or_404(SavedSearch, id=id, user=request.user)
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
query.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2008-08-28 11:06:24 +02:00
|
|
|
else:
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/confirm_delete_saved_query.html', {'query': query})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-01-11 01:26:00 +01:00
|
|
|
delete_saved_query = staff_member_required(delete_saved_query)
|
2008-09-09 10:32:01 +02:00
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
class EditUserSettingsView(MustBeStaffMixin, UpdateView):
|
|
|
|
template_name = 'helpdesk/user_settings.html'
|
|
|
|
form_class = UserSettingsForm
|
|
|
|
model = UserSettings
|
|
|
|
success_url = reverse_lazy('helpdesk:dashboard')
|
2017-12-06 08:06:07 +01:00
|
|
|
|
2018-10-05 14:54:22 +02:00
|
|
|
def get_object(self):
|
|
|
|
return UserSettings.objects.get_or_create(user=self.request.user)[0]
|
2008-10-25 00:52:34 +02:00
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_superuser_required
|
2008-10-25 00:52:34 +02:00
|
|
|
def email_ignore(request):
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/email_ignore_list.html', {
|
|
|
|
'ignore_list': IgnoreEmail.objects.all(),
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
email_ignore = superuser_required(email_ignore)
|
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_superuser_required
|
2008-10-25 00:52:34 +02:00
|
|
|
def email_ignore_add(request):
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = EmailIgnoreForm(request.POST)
|
|
|
|
if form.is_valid():
|
2016-10-21 17:14:12 +02:00
|
|
|
form.save()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:email_ignore'))
|
2008-10-25 00:52:34 +02:00
|
|
|
else:
|
|
|
|
form = EmailIgnoreForm(request.GET)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/email_ignore_add.html', {'form': form})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
email_ignore_add = superuser_required(email_ignore_add)
|
|
|
|
|
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_superuser_required
|
2008-10-25 00:52:34 +02:00
|
|
|
def email_ignore_del(request, id):
|
|
|
|
ignore = get_object_or_404(IgnoreEmail, id=id)
|
|
|
|
if request.method == 'POST':
|
|
|
|
ignore.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:email_ignore'))
|
2008-10-25 00:52:34 +02:00
|
|
|
else:
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/email_ignore_del.html', {'ignore': ignore})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2008-10-25 00:52:34 +02:00
|
|
|
email_ignore_del = superuser_required(email_ignore_del)
|
2009-09-09 10:47:48 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2009-09-09 10:47:48 +02:00
|
|
|
def ticket_cc(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2015-12-16 17:51:15 +01:00
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
copies_to = ticket.ticketcc_set.all()
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket_cc_list.html', {
|
|
|
|
'copies_to': copies_to,
|
|
|
|
'ticket': ticket,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
ticket_cc = staff_member_required(ticket_cc)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2009-09-09 10:47:48 +02:00
|
|
|
def ticket_cc_add(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2015-12-16 17:51:15 +01:00
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
form = TicketCCForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
ticketcc = form.save(commit=False)
|
|
|
|
ticketcc.ticket = ticket
|
|
|
|
ticketcc.save()
|
2016-10-24 08:04:31 +02:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:ticket_cc',
|
2016-10-21 17:14:12 +02:00
|
|
|
kwargs={'ticket_id': ticket.id}))
|
2009-09-09 10:47:48 +02:00
|
|
|
else:
|
2016-09-12 08:11:55 +02:00
|
|
|
form_email = TicketCCEmailForm()
|
|
|
|
form_user = TicketCCUserForm()
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket_cc_add.html', {
|
|
|
|
'ticket': ticket,
|
2016-10-29 09:47:15 +02:00
|
|
|
'form_email': form_email,
|
|
|
|
'form_user': form_user,
|
2016-10-21 17:14:12 +02:00
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
ticket_cc_add = staff_member_required(ticket_cc_add)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2009-09-09 10:47:48 +02:00
|
|
|
def ticket_cc_del(request, ticket_id, cc_id):
|
|
|
|
cc = get_object_or_404(TicketCC, ticket__id=ticket_id, id=cc_id)
|
2015-12-16 17:51:15 +01:00
|
|
|
|
2010-01-26 01:01:22 +01:00
|
|
|
if request.method == 'POST':
|
2009-09-09 10:47:48 +02:00
|
|
|
cc.delete()
|
2016-10-24 08:04:31 +02:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:ticket_cc',
|
2016-10-21 17:14:12 +02:00
|
|
|
kwargs={'ticket_id': cc.ticket.id}))
|
|
|
|
return render(request, 'helpdesk/ticket_cc_del.html', {'cc': cc})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2009-09-09 10:47:48 +02:00
|
|
|
ticket_cc_del = staff_member_required(ticket_cc_del)
|
2011-05-10 11:27:11 +02:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2011-05-10 11:27:11 +02:00
|
|
|
def ticket_dependency_add(request, ticket_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2011-05-10 11:27:11 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
form = TicketDependencyForm(request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
ticketdependency = form.save(commit=False)
|
|
|
|
ticketdependency.ticket = ticket
|
2015-04-28 01:13:54 +02:00
|
|
|
if ticketdependency.ticket != ticketdependency.depends_on:
|
2011-05-10 11:27:11 +02:00
|
|
|
ticketdependency.save()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket.id]))
|
2011-05-10 11:27:11 +02:00
|
|
|
else:
|
|
|
|
form = TicketDependencyForm()
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket_dependency_add.html', {
|
|
|
|
'ticket': ticket,
|
|
|
|
'form': form,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
ticket_dependency_add = staff_member_required(ticket_dependency_add)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2011-05-10 11:27:11 +02:00
|
|
|
def ticket_dependency_del(request, ticket_id, dependency_id):
|
|
|
|
dependency = get_object_or_404(TicketDependency, ticket__id=ticket_id, id=dependency_id)
|
|
|
|
if request.method == 'POST':
|
|
|
|
dependency.delete()
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket_id]))
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/ticket_dependency_del.html', {'dependency': dependency})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2011-05-10 11:27:11 +02:00
|
|
|
ticket_dependency_del = staff_member_required(ticket_dependency_del)
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2014-07-28 11:46:02 +02:00
|
|
|
@helpdesk_staff_member_required
|
2011-11-19 09:34:07 +01:00
|
|
|
def attachment_del(request, ticket_id, attachment_id):
|
|
|
|
ticket = get_object_or_404(Ticket, id=ticket_id)
|
2019-10-11 17:12:39 +02:00
|
|
|
ticket_perm_check(request, ticket)
|
2016-09-12 08:11:55 +02:00
|
|
|
|
2019-03-29 15:17:10 +01:00
|
|
|
attachment = get_object_or_404(FollowUpAttachment, id=attachment_id)
|
2016-09-12 08:11:55 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
attachment.delete()
|
2016-11-11 04:31:37 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:view', args=[ticket_id]))
|
2016-10-29 09:47:15 +02:00
|
|
|
return render(request, 'helpdesk/ticket_attachment_del.html', {
|
|
|
|
'attachment': attachment,
|
|
|
|
'filename': attachment.filename,
|
|
|
|
})
|
2017-12-06 08:06:07 +01:00
|
|
|
|
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
def calc_average_nbr_days_until_ticket_resolved(Tickets):
|
|
|
|
nbr_closed_tickets = len(Tickets)
|
|
|
|
days_per_ticket = 0
|
|
|
|
days_each_ticket = list()
|
|
|
|
|
|
|
|
for ticket in Tickets:
|
|
|
|
time_ticket_open = ticket.modified - ticket.created
|
|
|
|
days_this_ticket = time_ticket_open.days
|
|
|
|
days_per_ticket += days_this_ticket
|
|
|
|
days_each_ticket.append(days_this_ticket)
|
|
|
|
|
2012-08-07 15:54:46 +02:00
|
|
|
if nbr_closed_tickets > 0:
|
|
|
|
mean_per_ticket = days_per_ticket / nbr_closed_tickets
|
|
|
|
else:
|
|
|
|
mean_per_ticket = 0
|
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
return mean_per_ticket
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2015-06-11 12:18:45 +02:00
|
|
|
def calc_basic_ticket_stats(Tickets):
|
2012-08-07 15:51:52 +02:00
|
|
|
# all not closed tickets (open, reopened, resolved,) - independent of user
|
2016-10-21 17:14:12 +02:00
|
|
|
all_open_tickets = Tickets.exclude(status=Ticket.CLOSED_STATUS)
|
2012-08-07 15:51:52 +02:00
|
|
|
today = datetime.today()
|
|
|
|
|
|
|
|
date_30 = date_rel_to_today(today, 30)
|
|
|
|
date_60 = date_rel_to_today(today, 60)
|
|
|
|
date_30_str = date_30.strftime('%Y-%m-%d')
|
|
|
|
date_60_str = date_60.strftime('%Y-%m-%d')
|
|
|
|
|
2014-07-21 09:12:27 +02:00
|
|
|
# > 0 & <= 30
|
2016-10-21 17:14:12 +02:00
|
|
|
ota_le_30 = all_open_tickets.filter(created__gte=date_30_str)
|
2012-08-07 15:51:52 +02:00
|
|
|
N_ota_le_30 = len(ota_le_30)
|
|
|
|
|
2014-07-21 09:12:27 +02:00
|
|
|
# >= 30 & <= 60
|
2016-10-21 17:14:12 +02:00
|
|
|
ota_le_60_ge_30 = all_open_tickets.filter(created__gte=date_60_str, created__lte=date_30_str)
|
2012-08-07 15:51:52 +02:00
|
|
|
N_ota_le_60_ge_30 = len(ota_le_60_ge_30)
|
|
|
|
|
2012-08-07 15:54:46 +02:00
|
|
|
# >= 60
|
2016-10-21 17:14:12 +02:00
|
|
|
ota_ge_60 = all_open_tickets.filter(created__lte=date_60_str)
|
2012-08-07 15:51:52 +02:00
|
|
|
N_ota_ge_60 = len(ota_ge_60)
|
|
|
|
|
|
|
|
# (O)pen (T)icket (S)tats
|
|
|
|
ots = list()
|
|
|
|
# label, number entries, color, sort_string
|
2016-10-29 09:47:15 +02:00
|
|
|
ots.append(['Tickets < 30 days', N_ota_le_30, 'success',
|
2016-10-21 17:14:12 +02:00
|
|
|
sort_string(date_30_str, ''), ])
|
2016-10-29 09:47:15 +02:00
|
|
|
ots.append(['Tickets 30 - 60 days', N_ota_le_60_ge_30,
|
|
|
|
'success' if N_ota_le_60_ge_30 == 0 else 'warning',
|
2016-10-21 17:14:12 +02:00
|
|
|
sort_string(date_60_str, date_30_str), ])
|
2016-10-29 09:47:15 +02:00
|
|
|
ots.append(['Tickets > 60 days', N_ota_ge_60,
|
|
|
|
'success' if N_ota_ge_60 == 0 else 'danger',
|
2016-10-21 17:14:12 +02:00
|
|
|
sort_string('', date_60_str), ])
|
2012-08-07 15:57:34 +02:00
|
|
|
|
|
|
|
# all closed tickets - independent of user.
|
2016-10-21 17:14:12 +02:00
|
|
|
all_closed_tickets = Tickets.filter(status=Ticket.CLOSED_STATUS)
|
|
|
|
average_nbr_days_until_ticket_closed = \
|
|
|
|
calc_average_nbr_days_until_ticket_resolved(all_closed_tickets)
|
2012-08-07 15:57:34 +02:00
|
|
|
# all closed tickets that were opened in the last 60 days.
|
2016-10-21 17:14:12 +02:00
|
|
|
all_closed_last_60_days = all_closed_tickets.filter(created__gte=date_60_str)
|
|
|
|
average_nbr_days_until_ticket_closed_last_60_days = \
|
|
|
|
calc_average_nbr_days_until_ticket_resolved(all_closed_last_60_days)
|
2012-08-07 15:57:34 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
# put together basic stats
|
2016-10-21 17:14:12 +02:00
|
|
|
basic_ticket_stats = {
|
|
|
|
'average_nbr_days_until_ticket_closed': average_nbr_days_until_ticket_closed,
|
|
|
|
'average_nbr_days_until_ticket_closed_last_60_days':
|
|
|
|
average_nbr_days_until_ticket_closed_last_60_days,
|
|
|
|
'open_ticket_stats': ots,
|
|
|
|
}
|
2012-08-07 15:51:52 +02:00
|
|
|
|
|
|
|
return basic_ticket_stats
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
def get_color_for_nbr_days(nbr_days):
|
|
|
|
if nbr_days < 5:
|
|
|
|
color_string = 'green'
|
2016-10-21 17:14:12 +02:00
|
|
|
elif nbr_days < 10:
|
2012-08-07 15:51:52 +02:00
|
|
|
color_string = 'orange'
|
2016-10-21 17:14:12 +02:00
|
|
|
else: # more than 10 days
|
2012-08-07 15:51:52 +02:00
|
|
|
color_string = 'red'
|
|
|
|
|
|
|
|
return color_string
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2012-08-07 15:51:52 +02:00
|
|
|
def days_since_created(today, ticket):
|
|
|
|
return (today - ticket.created).days
|
|
|
|
|
|
|
|
|
|
|
|
def date_rel_to_today(today, offset):
|
2016-10-23 22:02:02 +02:00
|
|
|
return today - timedelta(days=offset)
|
2012-08-07 15:51:52 +02:00
|
|
|
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
def sort_string(begin, end):
|
|
|
|
return 'sort=created&date_from=%s&date_to=%s&status=%s&status=%s&status=%s' % (
|
|
|
|
begin, end, Ticket.OPEN_STATUS, Ticket.REOPENED_STATUS, Ticket.RESOLVED_STATUS)
|