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.
38 lines
1.1 KiB
38 lines
1.1 KiB
6 years ago
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
import logging
|
||
|
from rest_framework.views import APIView, Response
|
||
|
from rest_framework_bulk import BulkModelViewSet
|
||
|
|
||
|
from common.utils import get_object_or_none
|
||
|
from common.permissions import IsOrgAdminOrAppUser
|
||
6 years ago
|
from ..models import Session, Task
|
||
|
from .. import serializers
|
||
6 years ago
|
|
||
|
|
||
|
__all__ = ['TaskViewSet', 'KillSessionAPI']
|
||
|
logger = logging.getLogger(__file__)
|
||
|
|
||
|
|
||
|
class TaskViewSet(BulkModelViewSet):
|
||
|
queryset = Task.objects.all()
|
||
|
serializer_class = serializers.TaskSerializer
|
||
|
permission_classes = (IsOrgAdminOrAppUser,)
|
||
|
|
||
|
|
||
|
class KillSessionAPI(APIView):
|
||
|
permission_classes = (IsOrgAdminOrAppUser,)
|
||
|
model = Task
|
||
|
|
||
|
def post(self, request, *args, **kwargs):
|
||
|
validated_session = []
|
||
|
for session_id in request.data:
|
||
|
session = get_object_or_none(Session, id=session_id)
|
||
|
if session and not session.is_finished:
|
||
|
validated_session.append(session_id)
|
||
|
self.model.objects.create(
|
||
|
name="kill_session", args=session.id,
|
||
|
terminal=session.terminal,
|
||
|
)
|
||
|
return Response({"ok": validated_session})
|