From 39f34ff4344622ca487a1be5f97c873935dd6129 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sat, 31 Oct 2020 15:23:49 +0100 Subject: [PATCH] [Plugin] Fixed return values for balance and roles routes --- flaschengeist/plugins/balance/__init__.py | 8 ++++++-- flaschengeist/plugins/roles/__init__.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/flaschengeist/plugins/balance/__init__.py b/flaschengeist/plugins/balance/__init__.py index b3ddfcb..5a24c8a 100644 --- a/flaschengeist/plugins/balance/__init__.py +++ b/flaschengeist/plugins/balance/__init__.py @@ -3,6 +3,7 @@ Extends users plugin with balance functions """ +from http.client import NO_CONTENT from datetime import datetime, timezone from flask import Blueprint, jsonify, request from werkzeug.exceptions import Forbidden, BadRequest @@ -79,6 +80,7 @@ def set_limit(userid, current_session: Session): except (TypeError, KeyError): raise BadRequest balance_controller.set_limit(user, limit) + return "", NO_CONTENT @balance_bp.route("/users//balance", methods=["GET"]) @@ -156,11 +158,13 @@ def change_balance(userid, current_session: Session): if (sender == current_session._user and sender.has_permission(permissions.SEND)) or ( sender != current_session._user and current_session._user.has_permission(permissions.SEND_OTHER) ): - return balance_controller.send(sender, user, data["amount"], current_session._user) + balance_controller.send(sender, user, data["amount"], current_session._user) + return "", NO_CONTENT elif (amount < 0 and current_session._user.has_permission(permissions.SUB)) or ( amount > 0 and current_session._user.has_permission(permissions.ADD) ): - return balance_controller.change_balance(user, data["amount"], current_session._user) + balance_controller.change_balance(user, data["amount"], current_session._user) + return "", NO_CONTENT raise Forbidden diff --git a/flaschengeist/plugins/roles/__init__.py b/flaschengeist/plugins/roles/__init__.py index edb6a37..b3710f6 100644 --- a/flaschengeist/plugins/roles/__init__.py +++ b/flaschengeist/plugins/roles/__init__.py @@ -3,8 +3,9 @@ Provides routes used to configure roles and permissions of users / roles. """ +from werkzeug.exceptions import BadRequest from flask import Blueprint, request, jsonify -from werkzeug.exceptions import NotFound, BadRequest +from http.client import CREATED, NO_CONTENT from flaschengeist.plugins import Plugin from flaschengeist.decorator import login_required @@ -58,6 +59,7 @@ def create_role(current_session): if "permissions" in data: permissions = data["permissions"] roleController.create_role(data["name"], permissions) + return "", CREATED @roles_bp.route("/roles/permissions", methods=["GET"]) @@ -119,6 +121,7 @@ def edit_role(role_name, current_session): if "permissions" in data: roleController.set_permissions(role, data["permissions"]) roleController.update_role(role) + return "", NO_CONTENT @roles_bp.route("/roles/", methods=["DELETE"]) @@ -137,3 +140,4 @@ def delete_role(role_name, current_session): """ role = roleController.get(role_name) roleController.delete(role) + return "", NO_CONTENT