2021-12-29 12:07:56 +00:00
|
|
|
from rest_framework.mixins import CreateModelMixin
|
|
|
|
from rest_framework import views
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework import status
|
|
|
|
|
|
|
|
from common.drf.api import JMSGenericViewSet
|
|
|
|
from tickets.models import TicketSession
|
|
|
|
from tickets.serializers import TicketSessionRelationSerializer
|
|
|
|
from terminal.serializers import SessionSerializer
|
|
|
|
from orgs.utils import tmp_to_root_org
|
|
|
|
|
|
|
|
|
|
|
|
class TicketSessionRelationViewSet(CreateModelMixin, JMSGenericViewSet):
|
2022-02-21 10:51:11 +00:00
|
|
|
queryset = TicketSession.objects.all()
|
2021-12-29 12:07:56 +00:00
|
|
|
serializer_class = TicketSessionRelationSerializer
|
|
|
|
|
|
|
|
|
2022-02-17 12:13:31 +00:00
|
|
|
# Todo: 放到上面的 ViewSet 中
|
2021-12-29 12:07:56 +00:00
|
|
|
class TicketSessionApi(views.APIView):
|
2022-03-15 09:32:54 +00:00
|
|
|
perm_model = TicketSession
|
2022-03-16 06:43:20 +00:00
|
|
|
rbac_perms = {
|
|
|
|
'*': ['tickets.view_ticket']
|
|
|
|
}
|
2021-12-29 12:07:56 +00:00
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
with tmp_to_root_org():
|
2022-04-12 06:25:49 +00:00
|
|
|
tid = self.kwargs['ticket_id']
|
|
|
|
ticket_session = TicketSession.objects.filter(ticket=tid).first()
|
|
|
|
if not ticket_session:
|
2021-12-29 12:07:56 +00:00
|
|
|
return Response(status=status.HTTP_404_NOT_FOUND)
|
|
|
|
|
2022-04-12 06:25:49 +00:00
|
|
|
session = ticket_session.session
|
2021-12-29 12:07:56 +00:00
|
|
|
serializer = SessionSerializer(session)
|
|
|
|
return Response(serializer.data)
|