perf: 资产授权添加协议

pull/11981/head
ibuler 2023-10-27 17:19:13 +08:00
parent f93979eb2d
commit ad8aba88a3
6 changed files with 20 additions and 9 deletions

View File

@ -6,4 +6,5 @@ from .label import *
from .mixin import *
from .node import *
from .platform import *
from .protocol import *
from .tree import *

View File

@ -2,8 +2,8 @@ from rest_framework.decorators import action
from rest_framework.mixins import ListModelMixin
from rest_framework.response import Response
from assets.const import AllTypes, Protocol
from assets.serializers import CategorySerializer, TypeSerializer, ProtocolSerializer
from assets.const import AllTypes
from assets.serializers import CategorySerializer, TypeSerializer
from common.api import JMSGenericViewSet
from common.permissions import IsValidUser
@ -14,7 +14,6 @@ class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
serializer_classes = {
'default': CategorySerializer,
'types': TypeSerializer,
'protocols': ProtocolSerializer,
}
permission_classes = (IsValidUser,)
@ -33,8 +32,3 @@ class CategoryViewSet(ListModelMixin, JMSGenericViewSet):
tp = request.query_params.get('type')
constraints = AllTypes.get_constraints(category, tp)
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)

View File

@ -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())

View File

@ -22,4 +22,3 @@ class CategorySerializer(serializers.Serializer):
class ProtocolSerializer(serializers.Serializer):
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'))
category = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Category'))

View File

@ -26,6 +26,7 @@ router.register(r'protocol-settings', api.PlatformProtocolViewSet, 'protocol-set
urlpatterns = [
# 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/tasks/', api.AssetsTaskCreateApi.as_view(), name='assets-task-create'),
path('assets/<uuid:pk>/perm-users/', api.AssetPermUserListApi.as_view(), name='asset-perm-user-list'),

View File

@ -70,6 +70,7 @@ class AccountsPermedSerializer(serializers.ModelSerializer):
class AssetPermedDetailSerializer(AssetPermedSerializer):
# 前面特意加了 permed避免返回的是资产本身的
permed_protocols = AssetProtocolsPermsSerializer(many=True, required=False, label=_('Protocols'))
permed_accounts = AccountsPermedSerializer(label=_("Accounts"), required=False, many=True)