Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requires_membership as Fixture chapter 13 #908

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading