mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
from rest_framework import viewsets
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from common.utils import lazyproperty
|
|
from .. import serializers, models, mixins
|
|
|
|
|
|
class TicketViewSet(mixins.TicketMixin, viewsets.ModelViewSet):
|
|
serializer_class = serializers.TicketSerializer
|
|
queryset = models.Ticket.objects.all()
|
|
|
|
|
|
class TicketCommentViewSet(viewsets.ModelViewSet):
|
|
serializer_class = serializers.CommentSerializer
|
|
|
|
def check_permissions(self, request):
|
|
ticket = self.ticket
|
|
if request.user == ticket.user or request.user in ticket.assignees.all():
|
|
return True
|
|
return False
|
|
|
|
def get_serializer_context(self):
|
|
context = super().get_serializer_context()
|
|
context['ticket'] = self.ticket
|
|
return context
|
|
|
|
@lazyproperty
|
|
def ticket(self):
|
|
ticket_id = self.kwargs.get('ticket_id')
|
|
ticket = get_object_or_404(models.Ticket, pk=ticket_id)
|
|
return ticket
|
|
|
|
def get_queryset(self):
|
|
queryset = self.ticket.comments.all()
|
|
return queryset
|