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
4 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
|
||
|
from rest_framework import viewsets, mixins
|
||
|
from django.shortcuts import get_object_or_404
|
||
|
from common.exceptions import JMSException
|
||
|
from common.utils import lazyproperty
|
||
|
from tickets import serializers
|
||
|
from tickets.models import Ticket
|
||
|
from tickets.permissions.comment import IsAssignee, IsApplicant, IsSwagger
|
||
|
|
||
|
|
||
|
__all__ = ['CommentViewSet']
|
||
|
|
||
|
|
||
|
class CommentViewSet(mixins.CreateModelMixin, viewsets.ReadOnlyModelViewSet):
|
||
|
serializer_class = serializers.CommentSerializer
|
||
|
permission_classes = (IsSwagger| IsAssignee | IsApplicant,)
|
||
|
|
||
|
@lazyproperty
|
||
|
def ticket(self):
|
||
|
if getattr(self, 'swagger_fake_view', False):
|
||
|
return None
|
||
|
ticket_id = self.request.query_params.get('ticket_id')
|
||
|
try:
|
||
|
ticket = get_object_or_404(Ticket, pk=ticket_id)
|
||
|
return ticket
|
||
|
except Exception as e:
|
||
|
raise JMSException(str(e))
|
||
|
|
||
|
def get_serializer_context(self):
|
||
|
context = super().get_serializer_context()
|
||
|
context['ticket'] = self.ticket
|
||
|
return context
|
||
|
|
||
|
def get_queryset(self):
|
||
|
queryset = self.ticket.comments.all()
|
||
|
return queryset
|