From 4e46ea1ca3b0743375b6adab05bf127b8e940ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sat, 17 Apr 2021 22:05:49 +0200 Subject: [PATCH] [balance] add get and modify limits for all users --- flaschengeist/plugins/balance/routes.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/flaschengeist/plugins/balance/routes.py b/flaschengeist/plugins/balance/routes.py index 1341e6e..b0ce3c9 100644 --- a/flaschengeist/plugins/balance/routes.py +++ b/flaschengeist/plugins/balance/routes.py @@ -99,6 +99,32 @@ def set_limit(userid, current_session: Session): 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//balance", methods=["GET"]) @login_required(permission=permissions.SHOW) def get_balance(userid, current_session: Session):