From 3f0a4b45f357073d69a7eddbedaa6413f5f6df41 Mon Sep 17 00:00:00 2001 From: Massimiliano Date: Thu, 15 Aug 2024 14:36:29 +0200 Subject: [PATCH] requires_membership as Fixture --- docs/chapter-13.rst | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/chapter-13.rst b/docs/chapter-13.rst index 64441a95..0bf213ad 100644 --- a/docs/chapter-13.rst +++ b/docs/chapter-13.rst @@ -444,11 +444,13 @@ enables the following syntax: groups = Tags(db.auth_user) - def requires_membership(group_name): - return Condition( - lambda: group_name in groups.get(auth.user_id), - exception=HTTP(404) - ) + 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('index') @action.uses(requires_membership('teacher'))