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 (327f37b -> 9714707)


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated (327f37b -> 9714707)
Date: Fri, 31 May 2019 15:20:32 +0200

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

marcello pushed a change to branch master
in repository bank.

    from 327f37b  5715.
     new d8320c6  inherit
     new 9714707  porting /history-range

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 talerbank/app/schemas.py | 53 +++++++++++-------------------------------------
 talerbank/app/views.py   | 44 ++++++++++++++++++++--------------------
 2 files changed, 34 insertions(+), 63 deletions(-)

diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py
index b75ff6a..01503a2 100644
--- a/talerbank/app/schemas.py
+++ b/talerbank/app/schemas.py
@@ -47,11 +47,10 @@ class URLParamValidationError(ValidationError):
         self.http_status_code = http_status_code
         super().__init__()
 
-
 ##
 # Form specification that validates GET parameters from a
 # /history request.
-class HistoryParams(forms.Form):
+class HistoryParamsBase(forms.Form):
     auth = forms.CharField(
         validators=[RegexValidator(
             "^basic$",
@@ -64,11 +63,6 @@ class HistoryParams(forms.Form):
             "^(omit|show)$",
             message="Only 'omit' or 'show' are valid")])
 
-    # FIXME: adjust min/max values.
-    delta = forms.IntegerField()
-    # FIXME: adjust min/max values.
-    start = forms.IntegerField(required=False)
-
     ordering = forms.CharField(
         required=False,
         empty_value="descending",
@@ -84,6 +78,17 @@ class HistoryParams(forms.Form):
     # FIXME: adjust min/max values.
     account_number = forms.IntegerField(required=False)
 
+
+class HistoryParams(HistoryParamsBase):
+    # FIXME: adjust min/max values.
+    delta = forms.IntegerField()
+    start = forms.IntegerField(required=False)
+
+class HistoryRangeParams(HistoryParamsBase):
+    # FIXME: adjust min/max values.
+    end = forms.IntegerField()
+    start = forms.IntegerField()
+
 ##
 # Exception class to be raised when a expected URL parameter
 # is not found.
@@ -201,32 +206,6 @@ REJECT_REQUEST_SCHEMA = {
     }
 }
 
-
-##
-# Definition for /history-range request URL parameters.
-HISTORY_RANGE_REQUEST_SCHEMA = {
-    "type": "object",
-    "properties": {
-        "auth": {"type": "string", "pattern": "^basic$"},
-        "cancelled": {"type": "string",
-                      "pattern": "^(omit|show)$",
-                      "required": False},
-        "start": {"type": "string",
-                  "pattern": r"^[0-9]+$"},
-        "end": {"type": "string",
-                "pattern": r"^[0-9]+$"},
-        "ordering": {"type": "string",
-                     "pattern": r"^(ascending|descending)$",
-                     "required": False},
-        "direction": {"type": "string",
-                      "pattern": r"^(debit|credit|both|cancel\+|cancel-)$"},
-        "account_number": {"type": "string",
-                           "pattern": "^([0-9]+)$",
-                           "required": False}
-    }
-}
-
-
 ##
 # Definition for /add/incoming request bodies.
 INCOMING_REQUEST_SCHEMA = {
@@ -296,13 +275,6 @@ def validate_reject(data):
     validate(data, REJECT_REQUEST_SCHEMA)
 
 ##
-# Check /history-range input data.
-#
-# @param data dict representing /history's GET parameters.
-def validate_history_range(data):
-    validate(data, HISTORY_RANGE_REQUEST_SCHEMA)
-
-##
 # Check wire details
 # (regardless of which endpoint triggered the check)
 #
@@ -340,7 +312,6 @@ def check_withdraw_session(data):
 def validate_data(request, data):
     switch = {
         "/reject": validate_reject,
-        "/history-range": validate_history_range,
         "/admin/add/incoming": validate_add_incoming,
         "/pin/verify": check_withdraw_session,
         "/pin/question": validate_pin_tan
diff --git a/talerbank/app/views.py b/talerbank/app/views.py
index 3d1f7bc..34a5b70 100644
--- a/talerbank/app/views.py
+++ b/talerbank/app/views.py
@@ -44,7 +44,7 @@ from django.shortcuts import render, redirect
 from datetime import datetime
 from .models import BankAccount, BankTransaction
 from .amount import Amount
-from .schemas import validate_data, HistoryParams, URLParamValidationError
+from .schemas import validate_data, HistoryParams, HistoryRangeParams, 
URLParamValidationError
 LOGGER = logging.getLogger(__name__)
 
 ##
@@ -704,28 +704,28 @@ def build_history_response(qs, cancelled, user_account):
 @require_GET
 @login_via_headers
 def serve_history_range(request, user_account):
-    validate_data(request, request.GET.dict())
 
-    # Ordering.
-    ordering = request.GET.get("ordering", "descending")
+    get_params = HistoryRangeParams(request.GET.dict())
+    if not get_params.is_valid():
+        raise URLParamValidationError(get_params.errors, 400)
+
+    start_td = datetime.fromtimestamp(
+        get_params.cleaned_data.get("start"))
+    end_td = datetime.fromtimestamp(
+        get_params.cleaned_data.get("end"))
+
+    qs = query_history_range(
+        user_account.bankaccount,
+        request.GET.get("direction"),
+        start_td,
+        end_td,
+        get_params.cleaned_data.get("ordering"))
+
+    history = build_history_response(
+        qs,
+        get_params.cleaned_data.get("cancelled"),
+        user_account)
 
-    # Note: those values got sanity-checked by "validate_data()"
-    start = int(request.GET.get("start"))
-    end = int(request.GET.get("end"))
-    
-    start_td = datetime.fromtimestamp(start)
-    end_td = datetime.fromtimestamp(end)
-
-    qs = query_history_range(user_account.bankaccount,
-                             request.GET.get("direction"),
-                             start_td,
-                             end_td,
-                             "descending" == ordering)
-
-    history = build_history_response(qs,
-                                     request.GET.get("cancelled",
-                                                     "show"),
-                                     user_account)
     if not history:
         return HttpResponse(status=204)
     return JsonResponse(dict(data=history), status=200)
@@ -741,7 +741,7 @@ def serve_history_range(request, user_account):
 def serve_history(request, user_account):
     get_params = HistoryParams(request.GET.dict())
     if not get_params.is_valid():
-      raise URLParamValidationError(get_params.errors, 400)
+        raise URLParamValidationError(get_params.errors, 400)
 
     delta = get_params.cleaned_data.get("delta")
     start = get_params.cleaned_data.get("start")

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



reply via email to

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