From d7afcb65787c38050667861d6c12d459071c2304 Mon Sep 17 00:00:00 2001 From: Georg Lehner Date: Thu, 6 Jun 2024 00:28:36 +0200 Subject: [PATCH] Reformat Resolves/Depends lists into tables. Allow adding/deleting of parent tickets --- helpdesk/forms.py | 8 ++ .../templates/helpdesk/ticket_desc_table.html | 75 ++++++++++++------- .../helpdesk/ticket_resolves_add.html | 37 +++++++++ helpdesk/urls.py | 10 +++ helpdesk/views/staff.py | 46 ++++++++++++ 5 files changed, 150 insertions(+), 26 deletions(-) create mode 100644 helpdesk/templates/helpdesk/ticket_resolves_add.html diff --git a/helpdesk/forms.py b/helpdesk/forms.py index eb77c2e6..87da3893 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -591,6 +591,14 @@ class TicketDependencyForm(forms.ModelForm): model = TicketDependency exclude = ('ticket',) +class TicketResolvesForm(forms.ModelForm): + ''' Adds this ticket as a dependency for a different ticket ''' + + class Meta: + model = TicketDependency + #exclude = ('depends_on',) + fields = ('ticket',) + class MultipleTicketSelectForm(forms.Form): tickets = forms.ModelMultipleChoiceField( diff --git a/helpdesk/templates/helpdesk/ticket_desc_table.html b/helpdesk/templates/helpdesk/ticket_desc_table.html index 7b9e0295..f5003625 100644 --- a/helpdesk/templates/helpdesk/ticket_desc_table.html +++ b/helpdesk/templates/helpdesk/ticket_desc_table.html @@ -130,37 +130,60 @@ {% if helpdesk_settings.HELPDESK_ENABLE_DEPENDENCIES_ON_TICKET != False %} - {% trans "Depends" %} - - + + {% trans "Resolves" %} + - {% for dep in ticket.ticketdependency.all %} - {% if forloop.first %}{% endif %} - {% empty %} - {% trans "This ticket has no dependencies." %} - {% endfor %} - - {% trans "Resolves" %} - - {% for parent in ticket.depends_on.all %} - {% if forloop.first %}{% endif %} + + + {% for resolves in ticket.depends_on.all %} + {% if forloop.first %}{% endif %} + + + + + + {% if forloop.last %}
+ + + {{ resolves.ticket.get_status_display }} + {{ resolves.ticket.ticket }} {{ resolves.ticket.title }} +
{% endif %} {% empty %} - {% trans "This ticket does not resolve any other" %} + {% trans "This ticket does not resolve any other" %} {% endfor %} + + + {% trans "Depends" %} + + + + + + {% for dep in dependencies %} + {% if forloop.first %}{% endif %} + + + + + {% if forloop.last %}
+ + + {{ dep.depends_on.get_status_display }} + {{ dep.depends_on.ticket }} {{ dep.depends_on.title }} + +
{% endif %} + {% empty %} + {% trans "This ticket has no dependencies." %} + {% endfor %} + + {% endif %} {% if ticket.kbitem %} diff --git a/helpdesk/templates/helpdesk/ticket_resolves_add.html b/helpdesk/templates/helpdesk/ticket_resolves_add.html new file mode 100644 index 00000000..66165dd0 --- /dev/null +++ b/helpdesk/templates/helpdesk/ticket_resolves_add.html @@ -0,0 +1,37 @@ +{% extends "helpdesk/base.html" %}{% load i18n %} + +{% block helpdesk_title %}{% trans "Add Ticket as Dependency" %}{% endblock %} + +{% block helpdesk_breadcrumb %} + + + +{% endblock %} + +{% block helpdesk_body %}{% blocktrans %} +

Add Ticket as Dependency

+ +

Ticket: {{ depends_on }}

+ +

Adding this ticket as dependency will stop you resolving the selected ticket until this ticket has been resolved or closed.

{% endblocktrans %} + +
+ +
+
{% for field in form %} +
+
{{ field }}
+ {% if field.errors %}
{{ field.errors }}
{% endif %} + {% if field.help_text %}
{{ field.help_text }}
{% endif %} + {% endfor %}
+
+ + + +{% csrf_token %}
+ +{% endblock %} diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 02345389..a374bce2 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -88,6 +88,16 @@ urlpatterns = [ staff.ticket_dependency_del, name="ticket_dependency_del", ), + path( + "tickets//resolves/add/", + staff.ticket_resolves_add, + name="ticket_resolves_add", + ), + path( + "tickets//resolves/delete//", + staff.ticket_resolves_del, + name="ticket_resolves_del", + ), path( "tickets//attachment_delete//", staff.attachment_del, diff --git a/helpdesk/views/staff.py b/helpdesk/views/staff.py index 8abb9e7b..0f230583 100644 --- a/helpdesk/views/staff.py +++ b/helpdesk/views/staff.py @@ -54,6 +54,7 @@ from helpdesk.forms import ( TicketCCUserForm, TicketDependencyForm, TicketForm, + TicketResolvesForm, UserSettingsForm ) from helpdesk.lib import queue_template_context, safe_template_context @@ -79,6 +80,7 @@ from helpdesk.user import HelpdeskUser from helpdesk.update_ticket import update_ticket, subscribe_to_ticket_updates, return_ticketccstring_and_show_subscribe import helpdesk.views.abstract_views as abstract_views from helpdesk.views.permissions import MustBeStaffMixin +import itertools import json import re from rest_framework import status @@ -422,8 +424,16 @@ def view_ticket(request, ticket_id): return redirect('helpdesk:edit_ticket_checklist', ticket.id, checklist.id) + open_dependencies = ticket.ticketdependency.filter(depends_on__status__in=Ticket.OPEN_STATUSES) + dependencies = [d for d in itertools.chain( + open_dependencies, + ticket.ticketdependency.all().difference(open_dependencies) + )] + return render(request, 'helpdesk/ticket.html', { 'ticket': ticket, + 'dependencies': dependencies, + 'open_dependencies': open_dependencies, 'submitter_userprofile_url': submitter_userprofile_url, 'form': form, 'active_users': users, @@ -1695,6 +1705,42 @@ def ticket_dependency_del(request, ticket_id, dependency_id): ticket_dependency_del = staff_member_required(ticket_dependency_del) +@helpdesk_staff_member_required +def ticket_resolves_add(request, ticket_id): + depends_on = get_object_or_404(Ticket, id=ticket_id) + ticket_perm_check(request, depends_on) + if request.method == 'POST': + form = TicketResolvesForm(request.POST) + if form.is_valid(): + ticketdependency = form.save(commit=False) + ticketdependency.depends_on = depends_on + if ticketdependency.ticket != ticketdependency.depends_on: + ticketdependency.save() + return HttpResponseRedirect(reverse('helpdesk:view', args=[depends_on.id])) + else: + form = TicketResolvesForm() + return render(request, 'helpdesk/ticket_resolves_add.html', { + 'depends_on': depends_on, + 'form': form, + }) + + +ticket_resolves_add = staff_member_required(ticket_resolves_add) + + +@helpdesk_staff_member_required +def ticket_resolves_del(request, ticket_id, dependency_id): + dependency = get_object_or_404( + TicketDependency, ticket__id=ticket_id, id=dependency_id) + depends_on_id = dependency.depends_on.id + if request.method == 'POST': + dependency.delete() + return HttpResponseRedirect(reverse('helpdesk:view', args=[depends_on_id])) + return render(request, 'helpdesk/ticket_dependency_del.html', {'dependency': dependency}) + +ticket_resolves_del = staff_member_required(ticket_resolves_del) + + @helpdesk_staff_member_required def attachment_del(request, ticket_id, attachment_id): ticket = get_object_or_404(Ticket, id=ticket_id)