[balance] add get and modify limits for all users
This commit is contained in:
parent
47c8121a04
commit
394eef2a9e
|
@ -99,6 +99,32 @@ def set_limit(userid, current_session: Session):
|
||||||
return HTTP.no_content()
|
return HTTP.no_content()
|
||||||
|
|
||||||
|
|
||||||
|
@BalancePlugin.blueprint.route("/users/balance/limit", methods=["GET", "PUT"])
|
||||||
|
@login_required(permission=permissions.SET_LIMIT)
|
||||||
|
def limits(current_session: Session):
|
||||||
|
"""Get, Modify limit of all users
|
||||||
|
|
||||||
|
Args:
|
||||||
|
current_ession: Session sent with Authorization Header
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
JSON encoded array of userid with limit or HTTP-error
|
||||||
|
"""
|
||||||
|
|
||||||
|
users = userController.get_users()
|
||||||
|
if request.method == "GET":
|
||||||
|
return jsonify([{"userid": user.userid, "limit": user.get_attribute("balance_limit")} for user in users])
|
||||||
|
|
||||||
|
data = request.get_json()
|
||||||
|
try:
|
||||||
|
limit = data["limit"]
|
||||||
|
except (TypeError, KeyError):
|
||||||
|
raise BadRequest
|
||||||
|
for user in users:
|
||||||
|
balance_controller.set_limit(user, limit)
|
||||||
|
return HTTP.no_content()
|
||||||
|
|
||||||
|
|
||||||
@BalancePlugin.blueprint.route("/users/<userid>/balance", methods=["GET"])
|
@BalancePlugin.blueprint.route("/users/<userid>/balance", methods=["GET"])
|
||||||
@login_required(permission=permissions.SHOW)
|
@login_required(permission=permissions.SHOW)
|
||||||
def get_balance(userid, current_session: Session):
|
def get_balance(userid, current_session: Session):
|
||||||
|
|
Loading…
Reference in New Issue