mirror of https://github.com/jumpserver/jumpserver
perf: 资产授权添加协议
parent
f93979eb2d
commit
ad8aba88a3
|
@ -6,4 +6,5 @@ from .label import *
|
||||||
from .mixin import *
|
from .mixin import *
|
||||||
from .node import *
|
from .node import *
|
||||||
from .platform import *
|
from .platform import *
|
||||||
|
from .protocol import *
|
||||||
from .tree import *
|
from .tree import *
|
||||||
|
|
|
@ -2,8 +2,8 @@ from rest_framework.decorators import action
|
||||||
from rest_framework.mixins import ListModelMixin
|
from rest_framework.mixins import ListModelMixin
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from assets.const import AllTypes, Protocol
|
from assets.const import AllTypes
|
||||||
from assets.serializers import CategorySerializer, TypeSerializer, ProtocolSerializer
|
from assets.serializers import CategorySerializer, TypeSerializer
|
||||||
from common.api import JMSGenericViewSet
|
from common.api import JMSGenericViewSet
|
||||||
from common.permissions import IsValidUser
|
from common.permissions import IsValidUser
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
|
||||||
serializer_classes = {
|
serializer_classes = {
|
||||||
'default': CategorySerializer,
|
'default': CategorySerializer,
|
||||||
'types': TypeSerializer,
|
'types': TypeSerializer,
|
||||||
'protocols': ProtocolSerializer,
|
|
||||||
}
|
}
|
||||||
permission_classes = (IsValidUser,)
|
permission_classes = (IsValidUser,)
|
||||||
|
|
||||||
|
@ -33,8 +32,3 @@ class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
|
||||||
tp = request.query_params.get('type')
|
tp = request.query_params.get('type')
|
||||||
constraints = AllTypes.get_constraints(category, tp)
|
constraints = AllTypes.get_constraints(category, tp)
|
||||||
return Response(constraints)
|
return Response(constraints)
|
||||||
|
|
||||||
@action(methods=['get'], detail=False)
|
|
||||||
def protocols(self, request, *args, **kwargs):
|
|
||||||
protocols = list(Protocol.protocols())
|
|
||||||
return self.get_paginated_response_from_queryset(protocols)
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
from rest_framework.generics import ListAPIView
|
||||||
|
|
||||||
|
from assets import serializers
|
||||||
|
from assets.const import Protocol
|
||||||
|
from common.permissions import IsValidUser
|
||||||
|
|
||||||
|
__all__ = ['ProtocolListApi']
|
||||||
|
|
||||||
|
|
||||||
|
class ProtocolListApi(ListAPIView):
|
||||||
|
serializer_class = serializers.ProtocolSerializer
|
||||||
|
permission_classes = (IsValidUser,)
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
return list(Protocol.protocols())
|
|
@ -22,4 +22,3 @@ class CategorySerializer(serializers.Serializer):
|
||||||
class ProtocolSerializer(serializers.Serializer):
|
class ProtocolSerializer(serializers.Serializer):
|
||||||
label = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Label'))
|
label = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Label'))
|
||||||
value = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Value'))
|
value = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Value'))
|
||||||
category = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Category'))
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ router.register(r'protocol-settings', api.PlatformProtocolViewSet, 'protocol-set
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# path('assets/<uuid:pk>/gateways/', api.AssetGatewayListApi.as_view(), name='asset-gateway-list'),
|
# path('assets/<uuid:pk>/gateways/', api.AssetGatewayListApi.as_view(), name='asset-gateway-list'),
|
||||||
|
path('protocols/', api.ProtocolListApi.as_view(), name='asset-protocol'),
|
||||||
path('assets/<uuid:pk>/tasks/', api.AssetTaskCreateApi.as_view(), name='asset-task-create'),
|
path('assets/<uuid:pk>/tasks/', api.AssetTaskCreateApi.as_view(), name='asset-task-create'),
|
||||||
path('assets/tasks/', api.AssetsTaskCreateApi.as_view(), name='assets-task-create'),
|
path('assets/tasks/', api.AssetsTaskCreateApi.as_view(), name='assets-task-create'),
|
||||||
path('assets/<uuid:pk>/perm-users/', api.AssetPermUserListApi.as_view(), name='asset-perm-user-list'),
|
path('assets/<uuid:pk>/perm-users/', api.AssetPermUserListApi.as_view(), name='asset-perm-user-list'),
|
||||||
|
|
|
@ -70,6 +70,7 @@ class AccountsPermedSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class AssetPermedDetailSerializer(AssetPermedSerializer):
|
class AssetPermedDetailSerializer(AssetPermedSerializer):
|
||||||
|
# 前面特意加了 permed,避免返回的是资产本身的
|
||||||
permed_protocols = AssetProtocolsPermsSerializer(many=True, required=False, label=_('Protocols'))
|
permed_protocols = AssetProtocolsPermsSerializer(many=True, required=False, label=_('Protocols'))
|
||||||
permed_accounts = AccountsPermedSerializer(label=_("Accounts"), required=False, many=True)
|
permed_accounts = AccountsPermedSerializer(label=_("Accounts"), required=False, many=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue