def role_list(): group_id = current_identity.get('group_id') if GROUP_SYS_ADMIN_ID == current_identity.get('group_id'): group_id = request.args.get('group_id', None, type=int) return get_roles(request.args.get('page', 1, type=int), request.args.get('per_page', 10, type=int), group_id=group_id, name=request.args.get('name'))
def group_modify(_id): if current_identity.get("group_id") not in (GROUP_SYS_ADMIN_ID, int(_id)): raise ArgumentError modify_group(group_id=_id, name=request.json.get('name'), kind=request.json.get('kind'))
def role_modify(): modify_role(request.json.get('id'), group_id=current_identity.get('group_id'), name=request.json.get('name'), menu=request.json.get('menu'), permissions=request.json.get('permissions', []), state=request.json.get('state'))
def organization_modify(): if ORGANIZATION_SYS_ADMIN_ID == current_identity.get('organization_id'): organization_bid = request.json.get('organization_bid') else: organization_bid = current_identity.get("organization_bid") if not organization_bid: return jsonify(code=RETCODE.PARAMERR, message="参数异常") isok, ret = modify_organization(organization_bid=organization_bid, name=request.json.get('name'), kind=request.json.get('kind')) if not isok: return jsonify(code=RETCODE.DATAERR, message=ret) return jsonify(code=RETCODE.OK, data={})
def subaccount_add(): username = request.json.get('username') name = request.json.get('name') phone = request.json.get('phone') email = request.json.get('email') password = request.json.get('password') role_id = request.json.get('role_id') if not username or not password: return jsonify(code=RETCODE.PARAMERR, message="请填写账号密码") user = get_user_by_username(username) if user: return jsonify(code=RETCODE.USERERR, message="此用户已注册") isok, user = modify_user( None, username=username, name=name, email=email, phone=phone, password=password, role_id=role_id, organization_id=current_identity.get('organization_id')) if not isok: return jsonify(code=RETCODE.DATAERR, message="注册失败") return jsonify(code=RETCODE.OK, data={})
def password_modify(): isok, ret = modify_user(current_identity.get('user_bid'), password=request.json.get('password'), new_password=request.json.get('new_password')) if not isok: return jsonify(code=RETCODE.USERERR, message=ret) return jsonify(code=RETCODE.OK, data={})
def organization_list(): organization_bid = current_identity.get('organization_bid') if ORGANIZATION_SYS_ADMIN_ID == current_identity.get('organization_id'): organization_bid = request.args.get('organization_bid', None, type=int) page = request.args.get('page', 1, type=int) per_page = request.args.get('per_page', 10, type=int) total, items = get_organizations(page, per_page, organization_bid=organization_bid, name=request.args.get('name')) return jsonify(code=RETCODE.OK, data={ 'items': items, 'total': total, 'page': page, 'per_page': per_page })
def group_list(): group_id = current_identity.get('group_id') if GROUP_SYS_ADMIN_ID != group_id: raise ArgumentError return get_groups(request.args.get('page', 1, type=int), request.args.get('per_page', 10, type=int), group_id=request.args.get('group_id'), name=request.args.get('name'))
def user_list(): group_id = current_identity.get('group_id') if GROUP_SYS_ADMIN_ID == group_id: group_id = request.args.get('group_id', None, type=int) return get_users(request.args.get('page', 1, type=int), request.args.get('per_page', 10, type=int), group_id=group_id, name=request.args.get('name'), email=request.args.get('email'), phone=request.args.get('phone'))
def role_modify(): isok, ret = modify_role( request.json.get('id'), organization_id=current_identity.get('organization_id'), name=request.json.get('name'), menu=request.json.get('menu'), permissions=request.json.get('permissions'), state=request.json.get('state')) if not isok: return jsonify(code=RETCODE.DATAERR, message=ret) return jsonify(code=RETCODE.OK, data={})
def user_modify(): if not request.json.get('bid'): return jsonify(code=RETCODE.PARAMERR, message="缺少参数") isok, ret = modify_user(request.json.get('bid'), user_id=current_identity.get('user_id'), username=request.json.get('username'), name=request.json.get('name'), email=request.json.get('email'), phone=request.json.get('phone'), password=request.json.get('password'), role_id=request.json.get('role_id')) if not isok: return jsonify(code=RETCODE.DATAERR, message=ret) return jsonify(code=RETCODE.OK, data={})
def subaccount_add(): name = request.json.get("name") password = request.json.get("password") role_id = request.json.get("role_id") if not name or not password or not role_id: raise ArgumentError user = get_user_by_name(name) if user: raise UserError(message="The user is registed") create_user(name=name, email=request.json.get("email"), phone=request.json.get("phone"), password=password, role_id=role_id, group_id=current_identity.get("group_id"))
def user_menu(): user_id = current_identity.get('user_id') menus = get_user_menu(user_id) return {"menus": menus}
def user_menu(): user_id = current_identity.get('user_id') menus = get_user_menu(user_id) return jsonify(code=RETCODE.OK, data={"menus": menus})