def update(self, request, *args, **kwargs): # pylint: disable=unused-argument ''' 调整成员 ''' group = self.get_object() data = json.loads(request.body.decode('utf-8')) subject = data.get('subject', '') if subject not in ['add', 'delete', 'sort', 'override', 'move_out']: raise ValidationError({ 'subject': 'thid field must be one of add, delete, sort, override' }) inplace = False # 目标组是否包括自身 group_uids = set(get_patch_scope(request)) if kwargs['uid'] in group_uids: inplace = True group_uids.remove(kwargs['uid']) groups = get_groups_from_uids(group_uids) users = get_users_from_uids(data.get('user_uids', [])) if subject == 'move_out': for another_node in groups: update_users_of_owner(another_node, users, 'add') if not inplace: update_users_of_owner(group, users, 'delete') update_users_of_owner(group, users, subject) return Response(UserListSerializer(group).data)
def update(self, request, *args, **kwargs): # pylint: disable=unused-argument ''' 调整成员 - add 将一批人加入该部门 - delete 将一批人从该部门删除 - move_out 将一批人从该部门移除,并加入到指定其他部门 等效于 self.delete + others.add 当不指定其他部门时,即`delete` ''' dept = self.get_object() data = json.loads(request.body.decode('utf-8')) subject = data.get('subject', '') if subject not in ['add', 'delete', 'sort', 'override', 'move_out']: raise ValidationError({ 'subject': 'thid field must be one of add, delete, sort, override, move_out' }) inplace = False # 目标部门是否包括自身 dept_uids = set(get_patch_scope(request)) if kwargs['uid'] in dept_uids: inplace = True dept_uids.remove(kwargs['uid']) depts = get_depts_from_uids(dept_uids) users = get_users_from_uids(data.get('user_uids', [])) if subject == 'move_out': for another_dept in depts: update_users_of_owner(another_dept, users, 'add') if not inplace: update_users_of_owner(dept, users, 'delete') else: update_users_of_owner(dept, users, subject) return Response(UserListSerializer(dept).data)