[acls] treat decorator as acl in route decorator
This commit is contained in:
parent
31878d971e
commit
74e0b3dc54
|
@ -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})
|
||||
|
|
|
@ -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,
|
||||
**{
|
||||
|
|
Loading…
Reference in New Issue