From f42d5956db39a0c810f17d5effeee522cd15937f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 20 Jan 2021 15:21:33 +0100 Subject: [PATCH] [Plugin] balance: Added shortcuts configuration for balance --- flaschengeist/plugins/balance/__init__.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/flaschengeist/plugins/balance/__init__.py b/flaschengeist/plugins/balance/__init__.py index a3b051d..26127e0 100644 --- a/flaschengeist/plugins/balance/__init__.py +++ b/flaschengeist/plugins/balance/__init__.py @@ -4,7 +4,7 @@ Extends users plugin with balance functions """ from datetime import datetime, timezone -from flask import Blueprint, request +from flask import Blueprint, request, jsonify from werkzeug.exceptions import Forbidden, BadRequest from flaschengeist import logger @@ -39,6 +39,27 @@ class BalancePlugin(Plugin): db.create_all() +@balance_bp.route("/users//balance/shortcuts", methods=["GET"]) +@login_required() +def get_shortcuts(userid, current_session: Session): + """Get set limit of an user + + Route: ``/users//balance/limit`` | Method: ``GET`` + + Args: + userid: Userid identifying the user + current_session: Session sent with Authorization Header + + Returns: + JSON object containing the limit (or Null if no limit set) or HTTP error + """ + if userid != current_session._user.userid: + raise Forbidden + + user = userController.get_user(userid) + return jsonify(user.get_attribute("balance_shortcuts", [-2, -1, -0.5])) + + @balance_bp.route("/users//balance/limit", methods=["GET"]) @login_required() def get_limit(userid, current_session: Session):