[Bugfix] 和资产相关的Serializer添加protocols字段; (#2800)

* [Bugfix] 和资产相关的Serializer添加protocols字段;

* [Bugfix] RemoteApp Form 修改过滤RDP协议资产

* [Bugfix] 修改小问题
pull/2803/head
BaiJiangJie 2019-06-17 16:46:01 +08:00 committed by GitHub
parent 7715e62def
commit 795807ddbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 40 deletions

View File

@ -5,7 +5,7 @@ from django.utils.translation import ugettext as _
from django import forms from django import forms
from orgs.mixins import OrgModelForm from orgs.mixins import OrgModelForm
from assets.models import Asset, SystemUser from assets.models import SystemUser, Protocol
from ..models import RemoteApp from ..models import RemoteApp
from .. import const from .. import const
@ -89,7 +89,7 @@ class RemoteAppCreateUpdateForm(RemoteAppTypeForms, OrgModelForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
field_asset = self.fields['asset'] field_asset = self.fields['asset']
field_asset.queryset = field_asset.queryset.filter( field_asset.queryset = field_asset.queryset.filter(
protocol=Asset.PROTOCOL_RDP protocols__name=Protocol.PROTOCOL_RDP
) )
field_system_user = self.fields['system_user'] field_system_user = self.fields['system_user']
field_system_user.queryset = field_system_user.queryset.filter( field_system_user.queryset = field_system_user.queryset.filter(

View File

@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
from common.utils import get_logger from common.utils import get_logger
from orgs.mixins import OrgModelForm from orgs.mixins import OrgModelForm
from ..models import Asset, AdminUser, Protocol from ..models import Asset, Protocol
logger = get_logger(__file__) logger = get_logger(__file__)

View File

@ -12,8 +12,8 @@ from ..models import Asset, Protocol
from .system_user import AssetSystemUserSerializer from .system_user import AssetSystemUserSerializer
__all__ = [ __all__ = [
'AssetSerializer', 'AssetGrantedSerializer', 'MyAssetGrantedSerializer', 'AssetSerializer', 'AssetGrantedSerializer', 'AssetSimpleSerializer',
'AssetAsNodeSerializer', 'AssetSimpleSerializer', 'ProtocolSerializer',
] ]
@ -115,16 +115,19 @@ class AssetSerializer(BulkSerializerMixin, OrgResourceSerializerMixin,
return instance return instance
class AssetAsNodeSerializer(serializers.ModelSerializer): # class AssetAsNodeSerializer(serializers.ModelSerializer):
class Meta: # protocols = ProtocolSerializer(many=True)
model = Asset #
fields = ['id', 'hostname', 'ip', 'platform', 'protocols'] # class Meta:
# model = Asset
# fields = ['id', 'hostname', 'ip', 'platform', 'protocols']
class AssetGrantedSerializer(serializers.ModelSerializer): class AssetGrantedSerializer(serializers.ModelSerializer):
""" """
被授权资产的数据结构 被授权资产的数据结构
""" """
protocols = ProtocolSerializer(many=True)
system_users_granted = AssetSystemUserSerializer(many=True, read_only=True) system_users_granted = AssetSystemUserSerializer(many=True, read_only=True)
system_users_join = serializers.SerializerMethodField() system_users_join = serializers.SerializerMethodField()
# nodes = NodeTMPSerializer(many=True, read_only=True) # nodes = NodeTMPSerializer(many=True, read_only=True)
@ -132,9 +135,9 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Asset model = Asset
fields = ( fields = (
"id", "hostname", "ip", "system_users_granted", "id", "hostname", "ip", "protocols", "system_users_granted",
"is_active", "system_users_join", "os", 'domain', "is_active", "system_users_join", "os", 'domain',
"platform", "comment", "protocols", "org_id", "org_name", "platform", "comment", "org_id", "org_name",
) )
@staticmethod @staticmethod
@ -143,21 +146,24 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
return ', '.join(system_users) return ', '.join(system_users)
class MyAssetGrantedSerializer(AssetGrantedSerializer): # class MyAssetGrantedSerializer(AssetGrantedSerializer):
""" # """
普通用户获取授权的资产定义的数据结构 # 普通用户获取授权的资产定义的数据结构
""" # """
# protocols = ProtocolSerializer(many=True)
class Meta: #
model = Asset # class Meta:
fields = ( # model = Asset
"id", "hostname", "system_users_granted", # fields = (
"is_active", "system_users_join", "org_name", # "id", "hostname", "system_users_granted",
"os", "platform", "comment", "org_id", "protocol" # "is_active", "system_users_join", "org_name",
) # "os", "platform", "comment", "org_id", "protocols"
# )
class AssetSimpleSerializer(serializers.ModelSerializer): class AssetSimpleSerializer(serializers.ModelSerializer):
protocols = ProtocolSerializer(many=True)
class Meta: class Meta:
model = Asset model = Asset
fields = ['id', 'hostname', 'port', 'ip', 'connectivity'] fields = ['id', 'hostname', 'ip', 'protocols', 'connectivity', 'port']

View File

@ -5,14 +5,13 @@ from rest_framework import serializers
from common.fields import StringManyToManyField from common.fields import StringManyToManyField
from perms.models import AssetPermission, Action from perms.models import AssetPermission, Action
from assets.models import Node, Asset, SystemUser from assets.models import Node
from assets.serializers import AssetGrantedSerializer from assets.serializers import AssetGrantedSerializer
__all__ = [ __all__ = [
'AssetPermissionCreateUpdateSerializer', 'AssetPermissionListSerializer', 'AssetPermissionCreateUpdateSerializer', 'AssetPermissionListSerializer',
'AssetPermissionUpdateUserSerializer', 'AssetPermissionUpdateAssetSerializer', 'AssetPermissionUpdateUserSerializer', 'AssetPermissionUpdateAssetSerializer',
'AssetPermissionNodeSerializer', 'GrantedNodeSerializer', 'AssetPermissionNodeSerializer', 'GrantedNodeSerializer',
'GrantedAssetSerializer', 'GrantedSystemUserSerializer',
'ActionSerializer', 'NodeGrantedSerializer', 'ActionSerializer', 'NodeGrantedSerializer',
] ]
@ -122,19 +121,21 @@ class GrantedNodeSerializer(serializers.ModelSerializer):
] ]
class GrantedAssetSerializer(serializers.ModelSerializer): # class GrantedAssetSerializer(serializers.ModelSerializer):
class Meta: # protocols = ProtocolSerializer(many=True)
model = Asset #
fields = [ # class Meta:
'id', 'hostname', 'ip', 'port', 'protocol', 'platform', # model = Asset
'domain', 'is_active', 'comment' # fields = [
] # 'id', 'hostname', 'ip', 'protocols', 'port', 'protocol',
# 'platform', 'domain', 'is_active', 'comment'
# ]
class GrantedSystemUserSerializer(serializers.ModelSerializer): # class GrantedSystemUserSerializer(serializers.ModelSerializer):
class Meta: # class Meta:
model = SystemUser # model = SystemUser
fields = [ # fields = [
'id', 'name', 'username', 'protocol', 'priority', # 'id', 'name', 'username', 'protocol', 'priority',
'login_mode', 'comment' # 'login_mode', 'comment'
] # ]