修复授权导入系统用户为空报错

pull/6117/head
fghbng@qq.com 2021-05-14 19:16:21 +08:00 committed by Jiangjie.Bai
parent 4382921c57
commit c7dfd0edce
1 changed files with 4 additions and 12 deletions

View File

@ -83,22 +83,14 @@ class AssetPermissionSerializer(BulkOrgResourceModelSerializer):
return queryset
def to_internal_value(self, data):
if not data['assets']:
data['assets'] = []
if not data['system_users']:
data['system_users'] = []
if not data['users']:
data['users'] = []
if not data['user_groups']:
data['user_groups'] = []
if not data['nodes']:
data['nodes'] = []
# 系统用户是必填项
system_users = data.get('system_users', [])
system_users_display = data.pop('system_users_display', '')
for i in range(len(system_users_display)):
system_user = SystemUser.objects.filter(name=system_users_display[i]).first()
if system_user and system_user.id not in data['system_users']:
data['system_users'].append(system_user.id)
if system_user and system_user.id not in system_users:
system_users.append(system_user.id)
data['system_users'] = system_users
return super().to_internal_value(data)
def perform_display_create(self, instance, **kwargs):