diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index 80c8466..15530e4 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -5,20 +5,21 @@ from starlette.authentication import UnauthenticatedUser """ Base ACL module that contains generic functions for domains ACL """ -def connected(func): +def public(*args, **kwargs) -> bool: + "Unlimited access" + return True + +def connected(fct=public): """ Decorator that checks if the user object of the request has been set """ - @wraps(func) + @wraps(fct) def caller(req, *args, **kwargs): if (not hasattr(req, 'user') or type(req.user) == UnauthenticatedUser or not hasattr(req.user, 'is_authenticated')): return False - return func(req, **{**kwargs, **req.path_params}) + return fct(req, **{**kwargs, **req.path_params}) return caller -def public(*args, **kwargs) -> bool: - "Unlimited access" - return True diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index 15dc790..d9dbc29 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -3,7 +3,7 @@ from functools import wraps import importlib import sys from typing import Callable, List, Tuple, Dict, Generator -from types import ModuleType +from types import ModuleType, FunctionType from halfapi.conf import (PROJECT_NAME, DB_NAME, HOST, PORT, PRODUCTION, DOMAINS) @@ -137,7 +137,9 @@ def api_acls(request): for domain in app.d_acl.keys(): res[domain] = {} for acl_name, fct in app.d_acl[domain].items(): - print( fct(request) ) - res[domain][acl_name] = fct(request) + ok = fct(request) + if isinstance(ok, FunctionType): + ok = fct()(request) + res[domain][acl_name] = ok return res