gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: Check if the user respe


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: Check if the user respects his debt threshold.
Date: Wed, 22 Mar 2017 23:52:10 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new 976763e  Check if the user respects his debt threshold.
976763e is described below

commit 976763e5e897cfb6d5ca2b66304cc73b57ea5ac8
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Mar 22 23:51:41 2017 +0100

    Check if the user respects his debt threshold.
---
 talerbank/app/views.py     | 14 ++++++++++++++
 talerbank/settings_base.py |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index be96de4..63ee611 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -42,6 +42,8 @@ from .models import BankAccount, BankTransaction
 
 logger = logging.getLogger(__name__)
 
+class DebtLimitExceededException(Exception):
+    pass
 
 class MyAuthenticationForm(django.contrib.auth.forms.AuthenticationForm):
     def __init__(self, *args, **kwargs):           
@@ -410,6 +412,18 @@ def wire_transfer(amount,
     else:
         credit_account.balance_obj = 
amounts.amount_sub(credit_account.balance_obj, amount)
             
+    # Check here if any account went beyond the allowed
+    # debit threshold.
+    threshold = amounts.parse_amount(settings.TALER_MAX_DEBT)
+    if debit_account.user.username == "Bank":
+        threshold = amounts.parse_amount(settings.TALER_MAX_DEBT_BANK)
+        
+    if 1 == amounts.amount_cmp(debit_account.balance_obj, threshold) \
+       and 0 != amounts.amount_cmp(amounts.get_zero(), threshold):
+        logger.error("Negative balance '%s' not allowed." % 
json.dumps(debit_account.balance_obj))
+        logger.info("Your threshold is: '%s'." % json.dumps(threshold))
+        raise DebtLimitExceededException()
+
     with transaction.atomic():
         debit_account.save()
         credit_account.save()
diff --git a/talerbank/settings_base.py b/talerbank/settings_base.py
index 0cc33ed..1011b21 100644
--- a/talerbank/settings_base.py
+++ b/talerbank/settings_base.py
@@ -174,6 +174,8 @@ STATIC_ROOT = '/tmp/talerbankstatic/'
 
 
 TALER_CURRENCY = tc.value_string("taler", "currency", required=True)
+TALER_MAX_DEBT = tc.value_string("bank", "MAX_DEBT", required=True)
+TALER_MAX_DEBT_BANK = tc.value_string("bank", "MAX_DEBT_BANK", required=True)
 TALER_DIGITS = 2
 TALER_PREDEFINED_ACCOUNTS = ['Tor', 'GNUnet', 'Taler', 'FSF', 'Tutorial']
 TALER_EXPECTS_DONATIONS = ['Tor', 'GNUnet', 'Taler', 'FSF']

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]