From 74e0b3dc5416379d0e8ef1179fd052dcf6657931 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Wed, 30 Sep 2020 10:42:58 +0200 Subject: [PATCH] [acls] treat decorator as acl in route decorator --- halfapi/lib/acl.py | 5 ++++- halfapi/lib/routes.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index 15530e4..fa8edd2 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -14,9 +14,12 @@ def connected(fct=public): """ @wraps(fct) def caller(req, *args, **kwargs): + print(fct) + print(req.user) if (not hasattr(req, 'user') - or type(req.user) == UnauthenticatedUser + or isinstance(req.user, UnauthenticatedUser) or not hasattr(req.user, 'is_authenticated')): + print('Connected is false') return False return fct(req, **{**kwargs, **req.path_params}) diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index d9dbc29..433225f 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -37,12 +37,19 @@ def route_acl_decorator(fct: Callable, params: List[Dict]): @wraps(fct) async def caller(req: Request, *args, **kwargs): for param in params: - if param.get('acl') and param['acl'](req, *args, **kwargs): + if param.get('acl'): """ We merge the 'acl' and 'keys' kwargs values to let the decorated function know which ACL function answered True, and other parameters that you'd need """ + passed = param['acl'](req, *args, **kwargs) + if isinstance(passed, FunctionType): + passed = param['acl']()(req, *args, **kwargs) + + if not passed: + continue + return await fct( req, *args, **{