2022-07-22 03:26:41 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from helpdesk.models import FollowUp, FollowUpAttachment, Ticket
|
|
|
|
from helpdesk.serializers import FollowUpAttachmentSerializer, FollowUpSerializer, TicketSerializer, UserSerializer
|
2022-03-31 17:19:49 +02:00
|
|
|
from rest_framework import viewsets
|
2022-07-22 03:26:41 +02:00
|
|
|
from rest_framework.mixins import CreateModelMixin
|
2022-03-31 17:19:49 +02:00
|
|
|
from rest_framework.permissions import IsAdminUser
|
2022-05-02 17:27:25 +02:00
|
|
|
from rest_framework.viewsets import GenericViewSet
|
2022-03-31 17:19:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TicketViewSet(viewsets.ModelViewSet):
|
|
|
|
"""
|
|
|
|
A viewset that provides the standard actions to handle Ticket
|
|
|
|
"""
|
|
|
|
queryset = Ticket.objects.all()
|
|
|
|
serializer_class = TicketSerializer
|
|
|
|
permission_classes = [IsAdminUser]
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
tickets = Ticket.objects.all()
|
|
|
|
for ticket in tickets:
|
|
|
|
ticket.set_custom_field_values()
|
|
|
|
return tickets
|
|
|
|
|
|
|
|
def get_object(self):
|
|
|
|
ticket = super().get_object()
|
|
|
|
ticket.set_custom_field_values()
|
|
|
|
return ticket
|
2022-05-02 17:27:25 +02:00
|
|
|
|
|
|
|
|
2022-06-24 22:22:08 +02:00
|
|
|
class FollowUpViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = FollowUp.objects.all()
|
|
|
|
serializer_class = FollowUpSerializer
|
|
|
|
permission_classes = [IsAdminUser]
|
|
|
|
|
|
|
|
|
2022-06-24 23:45:26 +02:00
|
|
|
class FollowUpAttachmentViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = FollowUpAttachment.objects.all()
|
|
|
|
serializer_class = FollowUpAttachmentSerializer
|
|
|
|
permission_classes = [IsAdminUser]
|
|
|
|
|
|
|
|
|
2022-05-02 17:27:25 +02:00
|
|
|
class CreateUserView(CreateModelMixin, GenericViewSet):
|
|
|
|
queryset = get_user_model().objects.all()
|
|
|
|
serializer_class = UserSerializer
|
2022-05-04 18:51:02 +02:00
|
|
|
permission_classes = [IsAdminUser]
|