From 9eca15d0365a640544d0f7db9557131dc449dcb8 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 27 Jan 2021 02:36:07 +0100 Subject: [PATCH] [Plugin] balance: Fix with reversed transaction and improvement on shortcuts. * Raise exception if transaction is already reversed. * Sort shortcuts --- flaschengeist/plugins/balance/__init__.py | 1 + flaschengeist/plugins/balance/balance_controller.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/flaschengeist/plugins/balance/__init__.py b/flaschengeist/plugins/balance/__init__.py index 23a44ff..54a0202 100644 --- a/flaschengeist/plugins/balance/__init__.py +++ b/flaschengeist/plugins/balance/__init__.py @@ -67,6 +67,7 @@ def get_shortcuts(userid, current_session: Session): data = request.get_json() if not isinstance(data, list) or not all(isinstance(n, (int, float)) for n in data): raise BadRequest + data.sort() user.set_attribute("balance_shortcuts", data) userController.persist() return no_content() diff --git a/flaschengeist/plugins/balance/balance_controller.py b/flaschengeist/plugins/balance/balance_controller.py index e305b0b..3bbb820 100644 --- a/flaschengeist/plugins/balance/balance_controller.py +++ b/flaschengeist/plugins/balance/balance_controller.py @@ -5,7 +5,7 @@ from sqlalchemy import func from datetime import datetime, timezone -from werkzeug.exceptions import BadRequest, NotFound +from werkzeug.exceptions import BadRequest, NotFound, Conflict from flaschengeist.database import db from flaschengeist.models.user import User @@ -109,6 +109,8 @@ def reverse_transaction(transaction: Transaction, author: User): transaction: Transaction to reverse author: User that wants the transaction to be reverted """ + if transaction.reversal: + raise Conflict reversal = send(transaction.receiver_, transaction.sender_, transaction.amount, author) reversal.reversal = transaction transaction.reversal = reversal