halfapi/halfapi/lib/acl.py
Maxime Alves LIRMM 0cd7c987e5 pylint lib/acl.py
2020-10-07 09:54:09 +02:00

30 lines
760 B
Python

#!/usr/bin/env python3
"""
Base ACL module that contains generic functions for domains ACL
"""
from functools import wraps
from starlette.authentication import UnauthenticatedUser
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(fct)
def caller(req, *args, **kwargs):
print(fct)
print(req.user)
if (not hasattr(req, 'user')
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})
return caller