From f5624e9a7d4a5f81f5d5f13c85cb614d20a2841b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Thu, 15 Apr 2021 22:55:41 +0200 Subject: [PATCH] [pricelist] add user options pricelist_view --- flaschengeist/plugins/pricelist/__init__.py | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/flaschengeist/plugins/pricelist/__init__.py b/flaschengeist/plugins/pricelist/__init__.py index e7a25e3..68205ba 100644 --- a/flaschengeist/plugins/pricelist/__init__.py +++ b/flaschengeist/plugins/pricelist/__init__.py @@ -536,7 +536,6 @@ 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): @@ -569,6 +568,39 @@ def get_columns(userid, current_session): return no_content() +@PriceListPlugin.blueprint.route("/users//pricelist", methods=["GET", "PUT"]) +@login_required() +def get_priclist_setting(userid, current_session): + """Get pricelistsetting of an user + + Route: ``/pricelist/user//pricelist`` | Method: ``GET`` or ``PUT`` + + POST-data: on ``PUT`` ``{value: boolean}`` + + Args: + userid: Userid identifying the user + current_session: Session sent wth Authorization Header + + Returns: + GET: JSON object containing the value as boolean or HTTP-error + PUT: HTTP-NoContent 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("pricelist_view", {"value": False})) + else: + data = request.get_json() + if not isinstance(data, dict) or not "value" in data or not isinstance(data["value"], bool): + raise BadRequest + user.set_attribute("pricelist_view", 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):