From 2d31cda66570dbcd33916a6b8d7e90bb6cc6f362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 15 Apr 2021 22:05:34 +0200 Subject: [PATCH] Revert "[pricelist] delete visibleColums" This reverts commit 2d45c0dab9a46648744c3c590ea8bb6fe7e75e12. Conflicts: flaschengeist/plugins/pricelist/__init__.py --- flaschengeist/plugins/pricelist/__init__.py | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index fce9659..e7a25e3 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -5,6 +5,7 @@ from werkzeug.local import LocalProxy from werkzeug.exceptions import BadRequest, Forbidden, Unauthorized from flaschengeist import logger +from flaschengeist.controller import userController from flaschengeist.plugins import Plugin from flaschengeist.utils.decorators import login_required, extract_session from flaschengeist.utils.HTTP import no_content @@ -535,6 +536,39 @@ def post_pricelist_settings_min_prices(current_session): return no_content() + +@PriceListPlugin.blueprint.route("/users//pricecalc_columns", methods=["GET", "PUT"]) +@login_required() +def get_columns(userid, current_session): + """Get pricecalc_columns of an user + + Route: ``/users//pricelist/pricecac_columns`` | Method: ``GET`` or ``PUT`` + POST-data: On ``PUT`` json encoded array of floats + + Args: + userid: Userid identifying the user + current_session: Session sent with Authorization Header + + Returns: + GET: JSON object containing the shortcuts as float array or HTTP error + PUT: HTTP-created or HTTP error + """ + if userid != current_session.user_.userid: + raise Forbidden + + user = userController.get_user(userid) + if request.method == "GET": + return jsonify(user.get_attribute("pricecalc_columns", [])) + else: + data = request.get_json() + if not isinstance(data, list) or not all(isinstance(n, str) for n in data): + raise BadRequest + data.sort(reverse=True) + user.set_attribute("pricecalc_columns", data) + userController.persist() + return no_content() + + @PriceListPlugin.blueprint.route("/drinks//picture", methods=["POST", "GET", "DELETE"]) @login_required(permission=permissions.EDIT) def set_picture(identifier, current_session):