serializer优化&&资产授权导入优化

This commit is contained in:
fghbng@qq.com
2021-04-30 11:32:33 +08:00
committed by Jiangjie.Bai
parent 9a92e24e50
commit 72f9d0d371
2 changed files with 5 additions and 6 deletions

View File

@@ -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 = {