Unverified Commit 795807dd authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

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

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

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

* [Bugfix] 修改小问题
parent 7715e62d
......@@ -5,7 +5,7 @@ from django.utils.translation import ugettext as _
from django import forms
from orgs.mixins import OrgModelForm
from assets.models import Asset, SystemUser
from assets.models import SystemUser, Protocol
from ..models import RemoteApp
from .. import const
......@@ -89,7 +89,7 @@ class RemoteAppCreateUpdateForm(RemoteAppTypeForms, OrgModelForm):
super().__init__(*args, **kwargs)
field_asset = self.fields['asset']
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.queryset = field_system_user.queryset.filter(
......
......@@ -6,7 +6,7 @@ from django.utils.translation import gettext_lazy as _
from common.utils import get_logger
from orgs.mixins import OrgModelForm
from ..models import Asset, AdminUser, Protocol
from ..models import Asset, Protocol
logger = get_logger(__file__)
......
......@@ -12,8 +12,8 @@ from ..models import Asset, Protocol
from .system_user import AssetSystemUserSerializer
__all__ = [
'AssetSerializer', 'AssetGrantedSerializer', 'MyAssetGrantedSerializer',
'AssetAsNodeSerializer', 'AssetSimpleSerializer',
'AssetSerializer', 'AssetGrantedSerializer', 'AssetSimpleSerializer',
'ProtocolSerializer',
]
......@@ -115,16 +115,19 @@ class AssetSerializer(BulkSerializerMixin, OrgResourceSerializerMixin,
return instance
class AssetAsNodeSerializer(serializers.ModelSerializer):
class Meta:
model = Asset
fields = ['id', 'hostname', 'ip', 'platform', 'protocols']
# class AssetAsNodeSerializer(serializers.ModelSerializer):
# protocols = ProtocolSerializer(many=True)
#
# class Meta:
# model = Asset
# fields = ['id', 'hostname', 'ip', 'platform', 'protocols']
class AssetGrantedSerializer(serializers.ModelSerializer):
"""
被授权资产的数据结构
"""
protocols = ProtocolSerializer(many=True)
system_users_granted = AssetSystemUserSerializer(many=True, read_only=True)
system_users_join = serializers.SerializerMethodField()
# nodes = NodeTMPSerializer(many=True, read_only=True)
......@@ -132,9 +135,9 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
class Meta:
model = Asset
fields = (
"id", "hostname", "ip", "system_users_granted",
"id", "hostname", "ip", "protocols", "system_users_granted",
"is_active", "system_users_join", "os", 'domain',
"platform", "comment", "protocols", "org_id", "org_name",
"platform", "comment", "org_id", "org_name",
)
@staticmethod
......@@ -143,21 +146,24 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
return ', '.join(system_users)
class MyAssetGrantedSerializer(AssetGrantedSerializer):
"""
普通用户获取授权的资产定义的数据结构
"""
class Meta:
model = Asset
fields = (
"id", "hostname", "system_users_granted",
"is_active", "system_users_join", "org_name",
"os", "platform", "comment", "org_id", "protocol"
)
# class MyAssetGrantedSerializer(AssetGrantedSerializer):
# """
# 普通用户获取授权的资产定义的数据结构
# """
# protocols = ProtocolSerializer(many=True)
#
# class Meta:
# model = Asset
# fields = (
# "id", "hostname", "system_users_granted",
# "is_active", "system_users_join", "org_name",
# "os", "platform", "comment", "org_id", "protocols"
# )
class AssetSimpleSerializer(serializers.ModelSerializer):
protocols = ProtocolSerializer(many=True)
class Meta:
model = Asset
fields = ['id', 'hostname', 'port', 'ip', 'connectivity']
fields = ['id', 'hostname', 'ip', 'protocols', 'connectivity', 'port']
......@@ -5,14 +5,13 @@ from rest_framework import serializers
from common.fields import StringManyToManyField
from perms.models import AssetPermission, Action
from assets.models import Node, Asset, SystemUser
from assets.models import Node
from assets.serializers import AssetGrantedSerializer
__all__ = [
'AssetPermissionCreateUpdateSerializer', 'AssetPermissionListSerializer',
'AssetPermissionUpdateUserSerializer', 'AssetPermissionUpdateAssetSerializer',
'AssetPermissionNodeSerializer', 'GrantedNodeSerializer',
'GrantedAssetSerializer', 'GrantedSystemUserSerializer',
'ActionSerializer', 'NodeGrantedSerializer',
]
......@@ -122,19 +121,21 @@ class GrantedNodeSerializer(serializers.ModelSerializer):
]
class GrantedAssetSerializer(serializers.ModelSerializer):
class Meta:
model = Asset
fields = [
'id', 'hostname', 'ip', 'port', 'protocol', 'platform',
'domain', 'is_active', 'comment'
]
class GrantedSystemUserSerializer(serializers.ModelSerializer):
class Meta:
model = SystemUser
fields = [
'id', 'name', 'username', 'protocol', 'priority',
'login_mode', 'comment'
]
# class GrantedAssetSerializer(serializers.ModelSerializer):
# protocols = ProtocolSerializer(many=True)
#
# class Meta:
# model = Asset
# fields = [
# 'id', 'hostname', 'ip', 'protocols', 'port', 'protocol',
# 'platform', 'domain', 'is_active', 'comment'
# ]
# class GrantedSystemUserSerializer(serializers.ModelSerializer):
# class Meta:
# model = SystemUser
# fields = [
# 'id', 'name', 'username', 'protocol', 'priority',
# 'login_mode', 'comment'
# ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment