From a5cb9c40ed1a726f6e2a60f47d1c7238cfd9b3a4 Mon Sep 17 00:00:00 2001 From: Massimiliano Date: Thu, 22 Aug 2024 12:26:50 +0200 Subject: [PATCH] Working example for Condition fixture Working example for Condition fixture that check if user belongs to a group --- docs/chapter-06.rst | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/docs/chapter-06.rst b/docs/chapter-06.rst index f179c1c7..85ad3a63 100644 --- a/docs/chapter-06.rst +++ b/docs/chapter-06.rst @@ -657,16 +657,9 @@ require that users action have specific group membership: groups = Tags(db.auth_user) - class requires_membership(Fixture): - def __init__(self, group): - self.__prerequisites__ = [auth.user] # you must have a user before you can check - self.group = group # store the group when action defined - def on_request(self, context): # will be called if the action is called - if self.group not in groups.get(auth.user_id): - raise HTTP(401) # check and do something - @action("payroll") - @action.uses(auth, requires_membership("employees")) + @action.uses(auth, + Condition(lambda: 'employees' in groups.get(auth.user_id), on_false=lambda: redirect('index'))) def payroll(): return