From 72f9d0d3719fa10c9adcb610a1c0dac8d7025212 Mon Sep 17 00:00:00 2001 From: "fghbng@qq.com" Date: Fri, 30 Apr 2021 11:32:33 +0800 Subject: [PATCH] =?UTF-8?q?serializer=E4=BC=98=E5=8C=96&&=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E6=8E=88=E6=9D=83=E5=AF=BC=E5=85=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/perms/serializers/asset/permission.py | 9 ++++----- apps/users/serializers/user.py | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/perms/serializers/asset/permission.py b/apps/perms/serializers/asset/permission.py index c553663e4..dcaffb82f 100644 --- a/apps/perms/serializers/asset/permission.py +++ b/apps/perms/serializers/asset/permission.py @@ -91,24 +91,23 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer): data['system_users'].append(system_user.id) return super().to_internal_value(data) - def perform_display_create(self, instance, **kwargs): # 用户 users_to_set = User.objects.filter( Q(name__in=kwargs.get('users_display')) | Q(username__in=kwargs.get('users_display')) ).distinct() - instance.users.add(users_to_set) + instance.users.add(*users_to_set) # 用户组 user_groups_to_set = UserGroup.objects.filter(name__in=kwargs.get('user_groups_display')).distinct() - instance.user_groups.add(user_groups_to_set) + instance.user_groups.add(*user_groups_to_set) # 资产 assets_to_set = Asset.objects.filter( Q(ip__in=kwargs.get('assets_display')) | Q(hostname__in=kwargs.get('assets_display')) ).distinct() - instance.assets.add(assets_to_set) + instance.assets.add(*assets_to_set) # 节点 nodes_to_set = Node.objects.filter(full_value__in=kwargs.get('nodes_display')).distinct() - instance.nodes.add(nodes_to_set) + instance.nodes.add(*nodes_to_set) def create(self, validated_data): display = { diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index eeadcaa2d..5b2c19d10 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -51,7 +51,7 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): # small 指的是 不需要计算的直接能从一张表中获取到的数据 fields_small = fields_mini + fields_write_only + [ 'email', 'wechat', 'phone', 'mfa_level', - 'source', 'source_display', + 'source', 'source_display', 'can_public_key_auth', 'need_update_password', 'mfa_enabled', 'is_valid', 'is_expired', 'is_active', # 布尔字段 'date_expired', 'date_joined', 'last_login', # 日期字段 'created_by', 'comment', # 通用字段