[users] add dynamic shortcuts for users

This commit is contained in:
Tim Gröger 2021-04-18 23:28:05 +02:00
parent 1e5304fe1e
commit 96e4e73f4b
1 changed files with 18 additions and 0 deletions

View File

@ -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/<userid>/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()