Browse Source

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

pull/6086/head
fghbng@qq.com 4 years ago committed by Jiangjie.Bai
parent
commit
72f9d0d371
  1. 9
      apps/perms/serializers/asset/permission.py
  2. 2
      apps/users/serializers/user.py

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

2
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', # 通用字段

Loading…
Cancel
Save