mirror of https://github.com/jumpserver/jumpserver
feat(terminal): 终端管理添加批量更新接口
parent
34b188bbe7
commit
1b052a8729
|
@ -1,4 +1,5 @@
|
|||
from rest_framework.viewsets import GenericViewSet, ModelViewSet
|
||||
from rest_framework_bulk import BulkModelViewSet
|
||||
|
||||
from ..mixins.api import (
|
||||
SerializerMixin2, QuerySetMixin, ExtraFilterFieldsMixin, PaginatedResponseMixin
|
||||
|
@ -19,3 +20,11 @@ class JMSModelViewSet(SerializerMixin2,
|
|||
PaginatedResponseMixin,
|
||||
ModelViewSet):
|
||||
pass
|
||||
|
||||
|
||||
class JMSBulkModelViewSet(SerializerMixin2,
|
||||
QuerySetMixin,
|
||||
ExtraFilterFieldsMixin,
|
||||
PaginatedResponseMixin,
|
||||
BulkModelViewSet):
|
||||
pass
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
from rest_framework.serializers import Serializer
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework import serializers
|
||||
from rest_framework_bulk.serializers import BulkListSerializer
|
||||
|
||||
from common.mixins.serializers import BulkSerializerMixin
|
||||
from common.mixins import BulkListSerializerMixin
|
||||
|
||||
__all__ = ['EmptySerializer', 'BulkModelSerializer']
|
||||
|
||||
|
||||
class EmptySerializer(Serializer):
|
||||
pass
|
||||
|
||||
|
||||
class BulkModelSerializer(BulkSerializerMixin, ModelSerializer):
|
||||
pass
|
||||
|
||||
|
||||
class AdaptedBulkListSerializer(BulkListSerializerMixin, BulkListSerializer):
|
||||
pass
|
||||
|
||||
|
||||
class CeleryTaskSerializer(serializers.Serializer):
|
||||
task = serializers.CharField(read_only=True)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
from rest_framework.exceptions import APIException
|
||||
from rest_framework import status
|
||||
|
||||
|
||||
class JMSException(APIException):
|
||||
pass
|
||||
status_code = status.HTTP_400_BAD_REQUEST
|
||||
|
|
|
@ -1,14 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
"""
|
||||
老的代码统一到 `apps/common/drf/serializers.py` 中,
|
||||
之后此文件废弃
|
||||
"""
|
||||
|
||||
from rest_framework_bulk.serializers import BulkListSerializer
|
||||
from rest_framework import serializers
|
||||
from .mixins import BulkListSerializerMixin
|
||||
|
||||
|
||||
class AdaptedBulkListSerializer(BulkListSerializerMixin, BulkListSerializer):
|
||||
pass
|
||||
|
||||
|
||||
class CeleryTaskSerializer(serializers.Serializer):
|
||||
task = serializers.CharField(read_only=True)
|
||||
from common.drf.serializers import AdaptedBulkListSerializer, CeleryTaskSerializer
|
||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: JumpServer 0.3.3\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2020-07-28 11:25+0800\n"
|
||||
"POT-Creation-Date: 2020-07-29 15:03+0800\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: ibuler <ibuler@qq.com>\n"
|
||||
"Language-Team: JumpServer team<ibuler@qq.com>\n"
|
||||
|
@ -2419,6 +2419,10 @@ msgstr "会话"
|
|||
msgid "Risk level"
|
||||
msgstr "风险等级"
|
||||
|
||||
#: terminal/exceptions.py:8
|
||||
msgid "Bulk create not support"
|
||||
msgstr "不支持批量创建"
|
||||
|
||||
#: terminal/models.py:27
|
||||
msgid "Remote Address"
|
||||
msgstr "远端地址"
|
||||
|
@ -2479,40 +2483,40 @@ msgstr "结束日期"
|
|||
msgid "Args"
|
||||
msgstr "参数"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:43
|
||||
#: tickets/api/request_asset_perm.py:42
|
||||
msgid "Ticket closed"
|
||||
msgstr "工单已关闭"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:46
|
||||
#: tickets/api/request_asset_perm.py:45
|
||||
#, python-format
|
||||
msgid "Ticket has %s"
|
||||
msgstr "工单已%s"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:93
|
||||
#: tickets/api/request_asset_perm.py:90
|
||||
msgid "Confirm assets first"
|
||||
msgstr "请先确认资产"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:96
|
||||
#: tickets/api/request_asset_perm.py:93
|
||||
msgid "Confirmed assets changed"
|
||||
msgstr "确认的资产变更了"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:100
|
||||
#: tickets/api/request_asset_perm.py:97
|
||||
msgid "Confirm system-user first"
|
||||
msgstr "请先确认系统用户"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:104
|
||||
#: tickets/api/request_asset_perm.py:101
|
||||
msgid "Confirmed system-user changed"
|
||||
msgstr "确认的系统用户变更了"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:107 xpack/plugins/cloud/models.py:202
|
||||
#: tickets/api/request_asset_perm.py:104 xpack/plugins/cloud/models.py:202
|
||||
msgid "Succeed"
|
||||
msgstr "成功"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:114
|
||||
#: tickets/api/request_asset_perm.py:111
|
||||
msgid "From request ticket: {} {}"
|
||||
msgstr "来自工单申请: {} {}"
|
||||
|
||||
#: tickets/api/request_asset_perm.py:116
|
||||
#: tickets/api/request_asset_perm.py:113
|
||||
msgid "{} request assets, approved by {}"
|
||||
msgstr "{} 申请资产,通过人 {}"
|
||||
|
||||
|
@ -2592,11 +2596,11 @@ msgstr "确认的系统用户"
|
|||
msgid "Invalid `org_id`"
|
||||
msgstr "无效的 `org_id`"
|
||||
|
||||
#: tickets/serializers/request_asset_perm.py:93
|
||||
#: tickets/serializers/request_asset_perm.py:92
|
||||
msgid "Field `assignees` must be organization admin or superuser"
|
||||
msgstr "字段 assignees 必须是组织管理员或者超级管理员"
|
||||
|
||||
#: tickets/serializers/request_asset_perm.py:143
|
||||
#: tickets/serializers/request_asset_perm.py:142
|
||||
#, python-brace-format
|
||||
msgid ""
|
||||
"\n"
|
||||
|
|
|
@ -5,17 +5,17 @@ import logging
|
|||
import uuid
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils import timezone
|
||||
from django.shortcuts import get_object_or_404
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.views import APIView, Response
|
||||
from rest_framework.permissions import AllowAny
|
||||
|
||||
|
||||
from common.drf.api import JMSBulkModelViewSet
|
||||
from common.utils import get_object_or_none
|
||||
from common.permissions import IsAppUser, IsOrgAdminOrAppUser, IsSuperUser
|
||||
from ..models import Terminal, Status, Session
|
||||
from .. import serializers
|
||||
from .. import exceptions
|
||||
|
||||
__all__ = [
|
||||
'TerminalViewSet', 'TerminalTokenApi', 'StatusViewSet', 'TerminalConfig',
|
||||
|
@ -23,13 +23,16 @@ __all__ = [
|
|||
logger = logging.getLogger(__file__)
|
||||
|
||||
|
||||
class TerminalViewSet(viewsets.ModelViewSet):
|
||||
class TerminalViewSet(JMSBulkModelViewSet):
|
||||
queryset = Terminal.objects.filter(is_deleted=False)
|
||||
serializer_class = serializers.TerminalSerializer
|
||||
permission_classes = (IsSuperUser,)
|
||||
filter_fields = ['name', 'remote_addr']
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
if isinstance(request.data, list):
|
||||
raise exceptions.BulkCreateNotSupport()
|
||||
|
||||
name = request.data.get('name')
|
||||
remote_ip = request.META.get('REMOTE_ADDR')
|
||||
x_real_ip = request.META.get('X-Real-IP')
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.exceptions import JMSException
|
||||
|
||||
|
||||
class BulkCreateNotSupport(JMSException):
|
||||
default_code = 'bulk_create_not_support'
|
||||
default_detail = _('Bulk create not support')
|
|
@ -1,18 +1,18 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from common.mixins import BulkSerializerMixin
|
||||
from common.serializers import AdaptedBulkListSerializer
|
||||
from common.drf.serializers import BulkModelSerializer, AdaptedBulkListSerializer
|
||||
from ..models import (
|
||||
Terminal, Status, Session, Task
|
||||
)
|
||||
|
||||
|
||||
class TerminalSerializer(serializers.ModelSerializer):
|
||||
class TerminalSerializer(BulkModelSerializer):
|
||||
session_online = serializers.SerializerMethodField()
|
||||
is_alive = serializers.BooleanField(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Terminal
|
||||
list_serializer_class = AdaptedBulkListSerializer
|
||||
fields = [
|
||||
'id', 'name', 'remote_addr', 'http_port', 'ssh_port',
|
||||
'comment', 'is_accepted', "is_active", 'session_online',
|
||||
|
@ -30,7 +30,7 @@ class StatusSerializer(serializers.ModelSerializer):
|
|||
model = Status
|
||||
|
||||
|
||||
class TaskSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
||||
class TaskSerializer(BulkModelSerializer):
|
||||
|
||||
class Meta:
|
||||
fields = '__all__'
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
|
||||
from django.urls import path, include, re_path
|
||||
from django.urls import path, re_path
|
||||
from rest_framework_bulk.routes import BulkRouter
|
||||
|
||||
from common import api as capi
|
||||
|
|
Loading…
Reference in New Issue