2021-12-29 12:07:56 +00:00
|
|
|
from rest_framework import views
|
|
|
|
from rest_framework import status
|
2022-11-18 03:30:31 +00:00
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.mixins import CreateModelMixin
|
2021-12-29 12:07:56 +00:00
|
|
|
|
2022-11-18 03:30:31 +00:00
|
|
|
from orgs.utils import tmp_to_root_org
|
2023-01-16 11:02:09 +00:00
|
|
|
from common.api import JMSGenericViewSet
|
2022-11-18 03:30:31 +00:00
|
|
|
from terminal.serializers import SessionSerializer
|
2021-12-29 12:07:56 +00:00
|
|
|
from tickets.models import TicketSession
|
|
|
|
from tickets.serializers import TicketSessionRelationSerializer
|
|
|
|
|
|
|
|
|
|
|
|
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)
|