From 96e4e73f4becd6aa475e87377a3a265054e5d5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Sun, 18 Apr 2021 23:28:05 +0200 Subject: [PATCH] [users] add dynamic shortcuts for users --- flaschengeist/plugins/users/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/flaschengeist/plugins/users/__init__.py b/flaschengeist/plugins/users/__init__.py index e5b08a6..8a0db58 100644 --- a/flaschengeist/plugins/users/__init__.py +++ b/flaschengeist/plugins/users/__init__.py @@ -231,3 +231,21 @@ def notifications(current_session): def remove_notifications(nid, current_session): userController.delete_notification(nid, current_session.user_) return no_content() + + +@UsersPlugin.blueprint.route("/users//shortcuts", methods=["GET", "PUT"]) +@login_required() +def shortcuts(userid, current_session): + if userid != current_session.user_.userid: + raise Forbidden + + user = userController.get_user(userid) + if request.method == "GET": + return jsonify(user.get_attribute("users_link_shortcuts", [])) + else: + data = request.get_json() + if not isinstance(data, list) or not all(isinstance(n, dict) for n in data): + raise BadRequest + user.set_attribute("users_link_shortcuts", data) + userController.persist() + return no_content()