diff --git a/helpdesk/serializers.py b/helpdesk/serializers.py index b5734c49..66264abf 100644 --- a/helpdesk/serializers.py +++ b/helpdesk/serializers.py @@ -4,7 +4,7 @@ from django.contrib.humanize.templatetags import humanize from rest_framework.exceptions import ValidationError from .forms import TicketForm -from .models import Ticket, CustomField +from .models import Ticket, CustomField, FollowUp from .lib import format_time_spent from .user import HelpdeskUser @@ -71,12 +71,22 @@ class DatatablesTicketSerializer(serializers.ModelSerializer): return obj.kbitem.title if obj.kbitem else "" +class FollowUpSerializer(serializers.ModelSerializer): + class Meta: + model = FollowUp + fields = ( + 'id', 'ticket', 'date', 'title', 'comment', 'public', 'user', 'new_status', 'message_id', 'time_spent' + ) + + class TicketSerializer(serializers.ModelSerializer): + followup_set = FollowUpSerializer(many=True, read_only=True) + class Meta: model = Ticket fields = ( 'id', 'queue', 'title', 'description', 'resolution', 'submitter_email', 'assigned_to', 'status', 'on_hold', - 'priority', 'due_date', 'merged_to' + 'priority', 'due_date', 'merged_to', 'followup_set' ) def __init__(self, *args, **kwargs): diff --git a/helpdesk/urls.py b/helpdesk/urls.py index 03924e98..4079fb28 100644 --- a/helpdesk/urls.py +++ b/helpdesk/urls.py @@ -17,7 +17,7 @@ from rest_framework.routers import DefaultRouter from helpdesk.decorators import helpdesk_staff_member_required, protect_view from helpdesk.views import feeds, staff, public, login from helpdesk import settings as helpdesk_settings -from helpdesk.views.api import TicketViewSet, CreateUserView +from helpdesk.views.api import TicketViewSet, CreateUserView, FollowUpViewSet if helpdesk_settings.HELPDESK_KB_ENABLED: from helpdesk.views import kb @@ -176,6 +176,7 @@ urlpatterns += [ if helpdesk_settings.HELPDESK_ACTIVATE_API_ENDPOINT: router = DefaultRouter() router.register(r"tickets", TicketViewSet, basename="ticket") + router.register(r"followups", FollowUpViewSet, basename="followups") router.register(r"users", CreateUserView, basename="user") urlpatterns += [re_path(r"^api/", include(router.urls))] diff --git a/helpdesk/views/api.py b/helpdesk/views/api.py index 266f821f..a77514a2 100644 --- a/helpdesk/views/api.py +++ b/helpdesk/views/api.py @@ -4,8 +4,8 @@ from rest_framework.viewsets import GenericViewSet from rest_framework.mixins import CreateModelMixin from django.contrib.auth import get_user_model -from helpdesk.models import Ticket -from helpdesk.serializers import TicketSerializer, UserSerializer +from helpdesk.models import Ticket, FollowUp +from helpdesk.serializers import TicketSerializer, UserSerializer, FollowUpSerializer class TicketViewSet(viewsets.ModelViewSet): @@ -28,6 +28,15 @@ class TicketViewSet(viewsets.ModelViewSet): return ticket +class FollowUpViewSet(viewsets.ModelViewSet): + """ + A viewset that provides the standard actions to handle FollowUp + """ + queryset = FollowUp.objects.all() + serializer_class = FollowUpSerializer + permission_classes = [IsAdminUser] + + class CreateUserView(CreateModelMixin, GenericViewSet): queryset = get_user_model().objects.all() serializer_class = UserSerializer