def approve(package): """ Processing the request of creating a school """ user = package.get('user') params = package.get('params') user_id = user.get('id') school_id = PermissionHelper.get_user_school(user_id) if school_id == 0: return Response.error_response("You are not in a school") permission = PermissionHelper.get_permission(user_id, school_id) if not PermissionManager.check_permission(permission, ActionType.Approve): return Response.error_response('Access Denied') params = package.get('params') apply_id = int(params.get(ParamType.ApplyId)) apply = SchoolApplyHelper.get_apply_by_id(apply_id) apply_user_id = apply.get('userid') if apply is None: return Response.error_response('No Apply') status = params.get(ParamType.Approve) if status == 'true': status = 1 else: status = 2 SchoolApplyHelper.judge_apply(apply_id, user_id, status) if status == 1: PermissionHelper.user_join_school(apply_user_id, school_id) return Response.checked_response('Approve Successed')
def add_user_to_school(testcase, schoolname): """add a user to school """ school = SchoolHelper.get_school_by_name(schoolname) school_id = school.get('id') response = testcase.client.get('/user/info/get', {'token': testcase.token}) response = analyse_response(response) data = response.get('data') user_id = data.get('user').get('id') PermissionHelper.user_join_school(user_id, school_id)