[Plugin] balance: Fix with reversed transaction and improvement on shortcuts.

* Raise exception if transaction is already reversed.
* Sort shortcuts
This commit is contained in:
Ferdinand Thiessen 2021-01-27 02:36:07 +01:00
parent ba25d6177a
commit 9eca15d036
2 changed files with 4 additions and 1 deletions

View File

@ -67,6 +67,7 @@ def get_shortcuts(userid, current_session: Session):
data = request.get_json() data = request.get_json()
if not isinstance(data, list) or not all(isinstance(n, (int, float)) for n in data): if not isinstance(data, list) or not all(isinstance(n, (int, float)) for n in data):
raise BadRequest raise BadRequest
data.sort()
user.set_attribute("balance_shortcuts", data) user.set_attribute("balance_shortcuts", data)
userController.persist() userController.persist()
return no_content() return no_content()

View File

@ -5,7 +5,7 @@
from sqlalchemy import func from sqlalchemy import func
from datetime import datetime, timezone 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.database import db
from flaschengeist.models.user import User from flaschengeist.models.user import User
@ -109,6 +109,8 @@ def reverse_transaction(transaction: Transaction, author: User):
transaction: Transaction to reverse transaction: Transaction to reverse
author: User that wants the transaction to be reverted author: User that wants the transaction to be reverted
""" """
if transaction.reversal:
raise Conflict
reversal = send(transaction.receiver_, transaction.sender_, transaction.amount, author) reversal = send(transaction.receiver_, transaction.sender_, transaction.amount, author)
reversal.reversal = transaction reversal.reversal = transaction
transaction.reversal = reversal transaction.reversal = reversal