diff --git a/docs/chapter-06.rst b/docs/chapter-06.rst index 30ea0b7e..f179c1c7 100644 --- a/docs/chapter-06.rst +++ b/docs/chapter-06.rst @@ -657,11 +657,13 @@ require that users action have specific group membership: 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("payroll") @action.uses(auth, requires_membership("employees"))