mirror of https://github.com/jumpserver/jumpserver
[Bugfix] 和资产相关的Serializer添加protocols字段; (#2800)
* [Bugfix] 和资产相关的Serializer添加protocols字段; * [Bugfix] RemoteApp Form 修改过滤RDP协议资产 * [Bugfix] 修改小问题pull/2803/head
parent
7715e62def
commit
795807ddbe
|
@ -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 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'
|
||||
]
|
||||
# class GrantedSystemUserSerializer(serializers.ModelSerializer):
|
||||
# class Meta:
|
||||
# model = SystemUser
|
||||
# fields = [
|
||||
# 'id', 'name', 'username', 'protocol', 'priority',
|
||||
# 'login_mode', 'comment'
|
||||
# ]
|
||||
|
|
Loading…
Reference in New Issue