[Plugin] balance: Allow debiting from own account if DEBIT_OWN is set

This commit is contained in:
Ferdinand Thiessen 2020-11-02 17:12:59 +01:00
parent d8100b129e
commit 03aefbb35a
3 changed files with 28 additions and 12 deletions

View File

@ -167,9 +167,13 @@ def change_balance(userid, current_session: Session):
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)
):
elif (
amount < 0
and (
(user == current_session._user and user.has_permission(permissions.DEBIT_OWN))
or current_session._user.has_permission(permissions.DEBIT)
)
) or (amount > 0 and current_session._user.has_permission(permissions.CREDIT)):
balance_controller.change_balance(user, data["amount"], current_session._user)
return "", NO_CONTENT

View File

@ -1,3 +1,8 @@
# German: Soll -> Abgang vom Konto
# Haben -> Zugang aufs Konto
# English: Debit -> from account
# Credit -> to account
from sqlalchemy import func
from datetime import datetime, timezone
from werkzeug.exceptions import BadRequest

View File

@ -1,17 +1,24 @@
# Show own and others balance
SHOW = "balance_show"
"""Show own balance"""
SHOW_OTHER = "balance_show_others"
# Credit balance
ADD = "balance_add"
# Debit balance
SUB = "balance_sub"
# Send from to other
"""Show others balance"""
CREDIT = "balance_credit"
"""Credit balances (give)"""
DEBIT = "balance_debit"
"""Debit balances (take)"""
DEBIT_OWN = "balance_debit_own"
"""Debit own balance"""
SEND = "balance_send"
# Send from other to another
"""Send from to other"""
SEND_OTHER = "balance_send_others"
# Can set limit for users
"""Send from other to another"""
SET_LIMIT = "balance_set_limit"
# Allow sending / sub while exceeding the set limit
"""Can set limit for users"""
EXCEED_LIMIT = "balance_exceed_limit"
"""Allow sending / sub while exceeding the set limit"""
permissions = [value for key, value in globals().items() if not key.startswith("_")]