From b92c83de39a922a7a2dd43a7f85ba9969edc5923 Mon Sep 17 00:00:00 2001 From: Timothy Hobbs Date: Thu, 23 Nov 2023 21:50:44 +0100 Subject: [PATCH] Implement My Tickets view in public helpdesk Note: This is a breaking change as it forces pagination on the API endoints. This should have been done from the start as the API without pagination is useless when there are large numbers of tickets. --- helpdesk/serializers.py | 40 +++++++++++ helpdesk/templates/helpdesk/my_tickets.html | 69 +++++++++++++++++++ .../helpdesk/navigation-sidebar.html | 9 +++ helpdesk/urls.py | 20 +++--- helpdesk/views/api.py | 24 ++++++- helpdesk/views/public.py | 15 +++- 6 files changed, 165 insertions(+), 12 deletions(-) create mode 100644 helpdesk/templates/helpdesk/my_tickets.html diff --git a/helpdesk/serializers.py b/helpdesk/serializers.py index 1217350e..0f43d303 100644 --- a/helpdesk/serializers.py +++ b/helpdesk/serializers.py @@ -70,6 +70,46 @@ class DatatablesTicketSerializer(serializers.ModelSerializer): return obj.kbitem.title if obj.kbitem else "" +class PublicTicketListingSerializer(serializers.ModelSerializer): + """ + A serializer to be used by the public API for listing tickets. Don't expose private fields here! + """ + ticket = serializers.SerializerMethodField() + submitter = serializers.SerializerMethodField() + created = serializers.SerializerMethodField() + due_date = serializers.SerializerMethodField() + status = serializers.SerializerMethodField() + queue = serializers.SerializerMethodField() + kbitem = serializers.SerializerMethodField() + + class Meta: + model = Ticket + # fields = '__all__' + fields = ('ticket', 'id', 'title', 'queue', 'status', + 'created', 'due_date', 'submitter', 'kbitem') + + def get_queue(self, obj): + return {"title": obj.queue.title, "id": obj.queue.id} + + def get_ticket(self, obj): + return str(obj.id) + " " + obj.ticket + + def get_status(self, obj): + return obj.get_status + + def get_created(self, obj): + return humanize.naturaltime(obj.created) + + def get_due_date(self, obj): + return humanize.naturaltime(obj.due_date) + + def get_submitter(self, obj): + return obj.submitter_email + + def get_kbitem(self, obj): + return obj.kbitem.title if obj.kbitem else "" + + class FollowUpAttachmentSerializer(serializers.ModelSerializer): class Meta: model = FollowUpAttachment diff --git a/helpdesk/templates/helpdesk/my_tickets.html b/helpdesk/templates/helpdesk/my_tickets.html new file mode 100644 index 00000000..2ec74f53 --- /dev/null +++ b/helpdesk/templates/helpdesk/my_tickets.html @@ -0,0 +1,69 @@ +{% extends "helpdesk/public_base.html" %}{% load i18n %} + +{% block helpdesk_body %} +

{% trans "My Tickets" %}

+ +
+ + + + + + + + + + + + + + +
TitleQueueStatusCreatedDue DateSubmitter
+ +
+ + + +{% endblock %} diff --git a/helpdesk/templates/helpdesk/navigation-sidebar.html b/helpdesk/templates/helpdesk/navigation-sidebar.html index 07c062f5..e42815f8 100644 --- a/helpdesk/templates/helpdesk/navigation-sidebar.html +++ b/helpdesk/templates/helpdesk/navigation-sidebar.html @@ -68,6 +68,15 @@ {% trans "New Ticket" %} + {% if user.is_authenticated %} + + + {% endif %} {% if helpdesk_settings.HELPDESK_KB_ENABLED %}