Skip to content

Commit

Permalink
fix(perm owner): fix the bug that the TypeError exception did not catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Oo-RR-oO committed Aug 19, 2020
1 parent e413353 commit 2e28178
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions siteapi/v1/views/perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,25 @@ def update(self, request, *args, **kwargs): # pylint: disable=unused-argument
UserPerm.valid_objects.filter(perm=perm).update(status='0')
DeptPerm.valid_objects.filter(perm=perm).update(status='0')
GroupPerm.valid_objects.filter(perm=perm).update(status='0')

user_perm_status = self.request.data.get('user_perm_status', [])
node_perm_status = self.request.data.get('node_perm_status', [])

if not isinstance(user_perm_status, list):
raise ValidationError({'user_perm_status': ['must be a list']})
if not isinstance(node_perm_status, list):
raise ValidationError({'node_perm_status': ['must be a list']})

for ups in user_perm_status:
user = User.valid_objects.filter(username=ups['uid']).first()
# TODO: 目前对每个对象都逐一检验 under_manage,开销大; 且对于没有权限的,只是静默跳过,没有提示。需改进。
if not (user and user.under_manage(request.user)):
raise ValidationError({'user_perm_status': [f'invlid uid: `{ups["uid"]}`']})
raise ValidationError({'user_perm_status': [f'invalid uid: `{ups["uid"]}`']})
ups['instance'] = user

node_perm_status = self.request.data.get('node_perm_status', [])
for nps in node_perm_status:
node, _ = Dept.retrieve_node(nps['uid'])
if not (node and node.under_manage(request.user)):
raise ValidationError({'node_perm_status': [f'invlid uid: `{nps["uid"]}`']})
raise ValidationError({'node_perm_status': [f'invalid uid: `{nps["uid"]}`']})
nps['instance'] = node

for ups in user_perm_status:
Expand Down

0 comments on commit 2e28178

Please sign in to comment.