[Plugin] balance: Fix with reversed transaction and improvement on shortcuts.
* Raise exception if transaction is already reversed. * Sort shortcuts
This commit is contained in:
parent
ba25d6177a
commit
9eca15d036
|
@ -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()
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue