Skip to content

Commit

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

0 comments on commit bf78d5f

Please sign in to comment.