def post(self, request, *args, **kwargs): request_data = request.data.get('data', {}) validator = CreateDepartmentMembersValidator(data=request_data) if not validator.is_valid(): return Response(console_response(code=1, msg=validator.errors)) department_id = validator.validated_data.get('department_id') member_type = validator.validated_data.get('member_type') validator = self.get_create_member_validator(member_type)( data=request_data) if not validator.is_valid(): return Response(console_response(code=1, msg=validator.errors)) member_info = validator.validated_data.get('member_info') member, error = AccountService.create(**member_info) if error: return Response( console_response(code=1, ret_set={}, msg='成员创建失败' + str(error))) elif DepartmentMemberService.join([member.user], department_id): # 创建成功 就加入到指定部门 if member.type in AccountType.FINANCE_TYPES: permission_group_id_list = validator.validated_data.get( 'permission_group_id_list') new_member = AccountService.get_by_owner(member.user) groups = PermissionGroupService.gets(permission_group_id_list) count = UserPermissionService.append_groups(new_member, groups) ret_set = DepartmentMemberService.to_dict(new_member) if count == len(permission_group_id_list): # create_payload = { # "owner": member.user.username, # "zone": request_data.get("zone", "bj") # } # create_resp = create_base_net(create_payload) # if create_resp.get("ret_code"): # return Response(console_response(code=1, msg="创建成员子网失败")) # ret_set["sub_net"] = create_resp.get("ret_set")[0] # return Response(console_response(ret_set=ret_set)) else: return Response( console_response(code=1, ret_set=ret_set, msg='成员初始化权限失败')) elif member.type in AccountType.PORTAL_TYPES: new_member = AccountService.get_by_owner(member.user) ret_set = DepartmentMemberService.to_dict(new_member) return Response(console_response(ret_set=ret_set)) else: AccountService.delete_by_username(member.user.username, really_delete=True) return Response( console_response(code=1, ret_set={}, msg='成员加入部门失败'))
def remove(cls, member_id_list): """ 删除用户 :param member_id_list: username 的列表 :return: """ try: for member_id in member_id_list: AccountService.delete_by_username(member_id) # delete_user_base_net(member_id) return True except Exception as e: logger.error(e.message) return False