2008-05-21 23:16:44 +02:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
|
|
|
|
|
|
|
views/public.py - All public facing views, eg non-staff (no authentication
|
|
|
|
required) views.
|
|
|
|
"""
|
2016-10-21 17:14:12 +02:00
|
|
|
from django.core.exceptions import ObjectDoesNotExist
|
2008-05-21 23:16:44 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2018-01-09 09:55:27 +01:00
|
|
|
from django.http import HttpResponseRedirect, HttpResponse
|
2016-10-21 17:14:12 +02:00
|
|
|
from django.shortcuts import render
|
2016-11-21 02:16:14 +01:00
|
|
|
from django.utils.http import urlquote
|
2008-05-21 23:16:44 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2018-01-09 09:55:27 +01:00
|
|
|
from django.conf import settings
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2011-06-09 17:24:33 +02:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
2017-10-04 03:42:26 +02:00
|
|
|
from helpdesk.decorators import protect_view
|
2008-05-21 23:16:44 +02:00
|
|
|
from helpdesk.forms import PublicTicketForm
|
2016-10-21 17:14:12 +02:00
|
|
|
from helpdesk.lib import text_is_spam
|
2012-03-01 23:28:54 +01:00
|
|
|
from helpdesk.models import Ticket, Queue, UserSettings, KBCategory
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2017-10-04 03:42:26 +02:00
|
|
|
@protect_view
|
2008-05-21 23:16:44 +02:00
|
|
|
def homepage(request):
|
2016-10-21 17:14:12 +02:00
|
|
|
if request.user.is_staff or \
|
2017-12-28 13:23:51 +01:00
|
|
|
(request.user.is_authenticated and
|
2016-10-21 17:14:12 +02:00
|
|
|
helpdesk_settings.HELPDESK_ALLOW_NON_STAFF_TICKET_UPDATE):
|
2011-02-04 01:40:15 +01:00
|
|
|
try:
|
2017-01-13 15:14:23 +01:00
|
|
|
if request.user.usersettings_helpdesk.settings.get('login_view_ticketlist', False):
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:list'))
|
2011-02-04 01:40:15 +01:00
|
|
|
else:
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:dashboard'))
|
2011-02-04 01:40:15 +01:00
|
|
|
except UserSettings.DoesNotExist:
|
2015-12-22 10:10:00 +01:00
|
|
|
return HttpResponseRedirect(reverse('helpdesk:dashboard'))
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
if request.method == 'POST':
|
2009-01-22 09:08:22 +01:00
|
|
|
form = PublicTicketForm(request.POST, request.FILES)
|
2016-10-21 17:14:12 +02:00
|
|
|
form.fields['queue'].choices = [('', '--------')] + [
|
|
|
|
(q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]
|
2008-05-21 23:16:44 +02:00
|
|
|
if form.is_valid():
|
2009-06-25 13:22:53 +02:00
|
|
|
if text_is_spam(form.cleaned_data['body'], request):
|
|
|
|
# This submission is spam. Let's not save it.
|
2016-06-21 07:18:06 +02:00
|
|
|
return render(request, template_name='helpdesk/public_spam.html')
|
2009-06-25 13:22:53 +02:00
|
|
|
else:
|
|
|
|
ticket = form.save()
|
2017-12-16 02:28:39 +01:00
|
|
|
try:
|
|
|
|
return HttpResponseRedirect('%s?ticket=%s&email=%s' % (
|
|
|
|
reverse('helpdesk:public_view'),
|
|
|
|
ticket.ticket_for_url,
|
|
|
|
urlquote(ticket.submitter_email))
|
|
|
|
)
|
|
|
|
except ValueError:
|
|
|
|
# if someone enters a non-int string for the ticket
|
|
|
|
return HttpResponseRedirect(reverse('helpdesk:home'))
|
2008-05-21 23:16:44 +02:00
|
|
|
else:
|
2008-10-07 08:52:52 +02:00
|
|
|
try:
|
|
|
|
queue = Queue.objects.get(slug=request.GET.get('queue', None))
|
|
|
|
except Queue.DoesNotExist:
|
|
|
|
queue = None
|
|
|
|
initial_data = {}
|
2018-01-09 09:55:27 +01:00
|
|
|
|
|
|
|
# add pre-defined data for public ticket
|
|
|
|
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_QUEUE'):
|
|
|
|
# get the requested queue; return an error if queue not found
|
|
|
|
try:
|
|
|
|
queue = Queue.objects.get(slug=settings.HELPDESK_PUBLIC_TICKET_QUEUE)
|
|
|
|
except Queue.DoesNotExist:
|
|
|
|
return HttpResponse(status=500)
|
|
|
|
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_PRIORITY'):
|
|
|
|
initial_data['priority'] = settings.HELPDESK_PUBLIC_TICKET_PRIORITY
|
|
|
|
if hasattr(settings, 'HELPDESK_PUBLIC_TICKET_DUE_DATE'):
|
|
|
|
initial_data['due_date'] = settings.HELPDESK_PUBLIC_TICKET_DUE_DATE
|
|
|
|
|
2008-10-07 08:52:52 +02:00
|
|
|
if queue:
|
|
|
|
initial_data['queue'] = queue.id
|
2009-08-04 14:04:13 +02:00
|
|
|
|
2017-12-28 13:23:51 +01:00
|
|
|
if request.user.is_authenticated and request.user.email:
|
2009-08-04 14:04:13 +02:00
|
|
|
initial_data['submitter_email'] = request.user.email
|
|
|
|
|
2008-10-07 08:52:52 +02:00
|
|
|
form = PublicTicketForm(initial=initial_data)
|
2016-10-21 17:14:12 +02:00
|
|
|
form.fields['queue'].choices = [('', '--------')] + [
|
|
|
|
(q.id, q.title) for q in Queue.objects.filter(allow_public_submission=True)]
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2012-03-01 23:28:54 +01:00
|
|
|
knowledgebase_categories = KBCategory.objects.all()
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/public_homepage.html', {
|
2016-10-23 22:02:02 +02:00
|
|
|
'form': form,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
'kb_categories': knowledgebase_categories
|
2016-10-21 17:14:12 +02:00
|
|
|
})
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2017-10-04 03:42:26 +02:00
|
|
|
@protect_view
|
2008-05-21 23:16:44 +02:00
|
|
|
def view_ticket(request):
|
2017-04-13 12:36:38 +02:00
|
|
|
ticket_req = request.GET.get('ticket', None)
|
|
|
|
email = request.GET.get('email', None)
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
if ticket_req and email:
|
2016-06-26 02:45:55 +02:00
|
|
|
queue, ticket_id = Ticket.queue_and_id_from_query(ticket_req)
|
2008-05-21 23:16:44 +02:00
|
|
|
try:
|
2016-06-24 03:46:37 +02:00
|
|
|
ticket = Ticket.objects.get(id=ticket_id, submitter_email__iexact=email)
|
2016-10-21 17:14:12 +02:00
|
|
|
except ObjectDoesNotExist:
|
2008-05-21 23:16:44 +02:00
|
|
|
error_message = _('Invalid ticket ID or e-mail address. Please try again.')
|
2018-01-11 20:49:21 +01:00
|
|
|
except ValueError:
|
|
|
|
error_message = _('Invalid ticket ID or e-mail address. Please try again.')
|
2016-10-21 17:14:12 +02:00
|
|
|
else:
|
2011-05-03 00:31:30 +02:00
|
|
|
if request.user.is_staff:
|
2015-12-22 10:10:00 +01:00
|
|
|
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'close' in request.GET:
|
2011-05-03 00:31:30 +02:00
|
|
|
redirect_url += '?close'
|
|
|
|
return HttpResponseRedirect(redirect_url)
|
2011-06-09 17:24:33 +02:00
|
|
|
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'close' in request.GET and ticket.status == Ticket.RESOLVED_STATUS:
|
2009-01-23 11:35:14 +01:00
|
|
|
from helpdesk.views.staff import update_ticket
|
|
|
|
# Trick the update_ticket() view into thinking it's being called with
|
|
|
|
# a valid POST.
|
|
|
|
request.POST = {
|
|
|
|
'new_status': Ticket.CLOSED_STATUS,
|
|
|
|
'public': 1,
|
|
|
|
'title': ticket.title,
|
|
|
|
'comment': _('Submitter accepted resolution and closed ticket'),
|
2016-10-23 22:02:02 +02:00
|
|
|
}
|
2011-04-28 12:23:16 +02:00
|
|
|
if ticket.assigned_to:
|
|
|
|
request.POST['owner'] = ticket.assigned_to.id
|
2009-01-23 11:35:14 +01:00
|
|
|
request.GET = {}
|
|
|
|
|
2009-07-22 10:19:46 +02:00
|
|
|
return update_ticket(request, ticket_id, public=True)
|
2011-06-09 17:24:33 +02:00
|
|
|
|
2011-11-23 19:56:36 +01:00
|
|
|
# redirect user back to this ticket if possible.
|
|
|
|
redirect_url = ''
|
|
|
|
if helpdesk_settings.HELPDESK_NAVIGATION_ENABLED:
|
2015-12-22 10:10:00 +01:00
|
|
|
redirect_url = reverse('helpdesk:view', args=[ticket_id])
|
2011-11-23 19:56:36 +01:00
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/public_view_ticket.html', {
|
|
|
|
'ticket': ticket,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
'next': redirect_url,
|
|
|
|
})
|
2017-04-13 12:36:38 +02:00
|
|
|
elif ticket_req is None and email is None:
|
|
|
|
error_message = None
|
2017-04-13 12:30:29 +02:00
|
|
|
else:
|
|
|
|
error_message = _('Missing ticket ID or e-mail address. Please try again.')
|
|
|
|
|
|
|
|
return render(request, 'helpdesk/public_view_form.html', {
|
|
|
|
'ticket': False,
|
|
|
|
'email': email,
|
|
|
|
'error_message': error_message,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
})
|
2016-10-21 17:14:12 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2011-11-27 09:26:56 +01:00
|
|
|
def change_language(request):
|
2011-11-27 09:43:51 +01:00
|
|
|
return_to = ''
|
2015-04-28 01:13:54 +02:00
|
|
|
if 'return_to' in request.GET:
|
2011-11-27 09:43:51 +01:00
|
|
|
return_to = request.GET['return_to']
|
|
|
|
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/public_change_language.html', {'next': return_to})
|