Skip to content

Commit

Permalink
requires_membership as Fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mbelletti authored Aug 15, 2024
1 parent 8736d37 commit 3f0a4b4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/chapter-13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit 3f0a4b4

Please sign in to comment.