2019-07-01 11:30:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
2019-07-11 10:12:14 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2019-07-01 11:30:18 +00:00
|
|
|
|
2022-08-17 03:54:18 +00:00
|
|
|
from assets.models import Node, Asset, Platform
|
2022-09-07 09:35:23 +00:00
|
|
|
from perms.serializers.permission import ActionsField
|
2019-07-01 11:30:18 +00:00
|
|
|
|
|
|
|
__all__ = [
|
2019-08-28 03:43:55 +00:00
|
|
|
'NodeGrantedSerializer',
|
|
|
|
'AssetGrantedSerializer',
|
2022-08-17 03:54:18 +00:00
|
|
|
'ActionsSerializer',
|
2019-07-01 11:30:18 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-10-22 10:13:14 +00:00
|
|
|
class AssetGrantedSerializer(serializers.ModelSerializer):
|
2020-10-22 09:05:47 +00:00
|
|
|
"""
|
2020-10-22 10:13:14 +00:00
|
|
|
被授权资产的数据结构
|
2020-10-22 09:05:47 +00:00
|
|
|
"""
|
2021-04-07 10:20:54 +00:00
|
|
|
platform = serializers.SlugRelatedField(
|
|
|
|
slug_field='name', queryset=Platform.objects.all(), label=_("Platform")
|
|
|
|
)
|
2020-10-22 10:13:14 +00:00
|
|
|
|
2020-10-22 09:05:47 +00:00
|
|
|
class Meta:
|
2020-10-22 10:13:14 +00:00
|
|
|
model = Asset
|
|
|
|
only_fields = [
|
2022-08-19 10:49:00 +00:00
|
|
|
"id", "name", "ip", "protocols", 'domain',
|
2020-10-22 10:13:14 +00:00
|
|
|
"platform", "comment", "org_id", "is_active"
|
|
|
|
]
|
|
|
|
fields = only_fields + ['org_name']
|
2020-10-22 09:05:47 +00:00
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
2020-10-22 10:13:14 +00:00
|
|
|
class NodeGrantedSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Node
|
|
|
|
fields = [
|
|
|
|
'id', 'name', 'key', 'value', 'org_id', "assets_amount"
|
|
|
|
]
|
|
|
|
read_only_fields = fields
|
|
|
|
|
|
|
|
|
|
|
|
class ActionsSerializer(serializers.Serializer):
|
|
|
|
actions = ActionsField(read_only=True)
|
|
|
|
|