diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index 4af7e14..9397d81 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -51,9 +51,9 @@ def args_check(fct): data_ = {} if req.method == 'GET': - data_ = req.query_params + data_ = dict(req.query_params) - if req.method in ['POST', 'PATCH', 'PUT', 'DELETE']: + elif req.method in ['POST', 'PATCH', 'PUT', 'DELETE']: try: data_ = await req.json() except JSONDecodeError as exc: diff --git a/halfapi/lib/constants.py b/halfapi/lib/constants.py index 294fec9..fa75ae1 100644 --- a/halfapi/lib/constants.py +++ b/halfapi/lib/constants.py @@ -3,7 +3,7 @@ from schema import Schema, Optional VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE') ACLS_SCHEMA = Schema([{ - 'acl': str, + 'acl': lambda fct: isinstance(fct(), bool), Optional('args'): { Optional('required'): { str }, Optional('optional'): { str } diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index 62df443..4589d11 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -21,6 +21,7 @@ import yaml from .domain import gen_router_routes, domain_acls, route_decorator from .responses import ORJSONResponse +from .acl import args_check from ..half_route import HalfRoute from ..conf import DOMAINSDICT @@ -75,7 +76,7 @@ def gen_schema_routes(schema: Dict): if not inspect.iscoroutinefunction(fct): yield HalfRoute(path, route_decorator(fct), acls, verb) else: - yield HalfRoute(path, fct, acls, verb) + yield HalfRoute(path, args_check(fct), acls, verb) def gen_starlette_routes(d_domains: Dict[str, ModuleType]) -> Generator: