From 03aefbb35a824522aedd6e5f2ef35956686a4186 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 2 Nov 2020 17:12:59 +0100 Subject: [PATCH] [Plugin] balance: Allow debiting from own account if DEBIT_OWN is set --- flaschengeist/plugins/balance/__init__.py | 10 +++++--- .../plugins/balance/balance_controller.py | 5 ++++ flaschengeist/plugins/balance/permissions.py | 25 ++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/flaschengeist/plugins/balance/__init__.py b/flaschengeist/plugins/balance/__init__.py index 295342f..862cdad 100644 --- a/flaschengeist/plugins/balance/__init__.py +++ b/flaschengeist/plugins/balance/__init__.py @@ -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 diff --git a/flaschengeist/plugins/balance/balance_controller.py b/flaschengeist/plugins/balance/balance_controller.py index a36bd91..596f9ce 100644 --- a/flaschengeist/plugins/balance/balance_controller.py +++ b/flaschengeist/plugins/balance/balance_controller.py @@ -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 diff --git a/flaschengeist/plugins/balance/permissions.py b/flaschengeist/plugins/balance/permissions.py index 43a13ee..713d204 100644 --- a/flaschengeist/plugins/balance/permissions.py +++ b/flaschengeist/plugins/balance/permissions.py @@ -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("_")]