From a719b4a31a1f43e0352c4a0ccc57d7378323b438 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Wed, 1 Jul 2020 10:15:42 +0200 Subject: [PATCH] ajout du decorateur "connected" --- halfapi/acl.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/halfapi/acl.py b/halfapi/acl.py index 380d77f..a540d3e 100644 --- a/halfapi/acl.py +++ b/halfapi/acl.py @@ -2,6 +2,17 @@ class BaseACL: """ Base ACL class that contains generic methods for domains ACL """ + def connected(req, func): + """ Decorator that checks if the user object of the request has been set + """ + def caller() + try: + getattr(req.user, 'is_authenticated') + return func() + except AttributeError: + return False + + return caller def public(self, *args) -> bool: "Unlimited access"