[Plugin] Fixed return values for balance and roles routes

This commit is contained in:
Ferdinand Thiessen 2020-10-31 15:23:49 +01:00
parent e5b39a6ef6
commit 39f34ff434
2 changed files with 11 additions and 3 deletions

View File

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

View File

@ -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/<role_name>", methods=["DELETE"])
@ -137,3 +140,4 @@ def delete_role(role_name, current_session):
"""
role = roleController.get(role_name)
roleController.delete(role)
return "", NO_CONTENT