mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-07-16 08:54:41 +00:00
* [Update] 控制组织管理员不允许编辑(更新、删除)超级用户 - 待续(控制批量更新API) * [Update] 修改方法名称 * [Update] 控制组织管理员不允许批量更新包含超级用户的用户列表 * [Bugfix] 修复所有ViewSet API进行批量更新时rest_framework_bulk库内部的bug * [Update] 修改 OpenID Middleware 日志输出模式 info => debug
54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
from rest_framework import serializers
|
|
|
|
from common.serializers import AdaptedBulkListSerializer
|
|
|
|
from ..models import Domain, Gateway
|
|
|
|
|
|
class DomainSerializer(serializers.ModelSerializer):
|
|
asset_count = serializers.SerializerMethodField()
|
|
gateway_count = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = Domain
|
|
fields = '__all__'
|
|
list_serializer_class = AdaptedBulkListSerializer
|
|
|
|
@staticmethod
|
|
def get_asset_count(obj):
|
|
return obj.assets.count()
|
|
|
|
@staticmethod
|
|
def get_gateway_count(obj):
|
|
return obj.gateway_set.all().count()
|
|
|
|
|
|
class GatewaySerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Gateway
|
|
list_serializer_class = AdaptedBulkListSerializer
|
|
fields = [
|
|
'id', 'name', 'ip', 'port', 'protocol', 'username',
|
|
'domain', 'is_active', 'date_created', 'date_updated',
|
|
'created_by', 'comment',
|
|
]
|
|
|
|
|
|
class GatewayWithAuthSerializer(GatewaySerializer):
|
|
def get_field_names(self, declared_fields, info):
|
|
fields = super().get_field_names(declared_fields, info)
|
|
fields.extend(
|
|
['password', 'private_key']
|
|
)
|
|
return fields
|
|
|
|
|
|
class DomainWithGatewaySerializer(serializers.ModelSerializer):
|
|
gateways = GatewayWithAuthSerializer(many=True, read_only=True)
|
|
|
|
class Meta:
|
|
model = Domain
|
|
fields = '__all__'
|