Skip to content
Discussion options

You must be logged in to vote

This is an excellent idea, and thank you for pointing out the inconsistency!

I've just added a require_all flag to both @roles_required and @permission_required.

To ensure backward compatibility:

  • @roles_required still defaults to require_all=False (OR logic).
  • @permission_required still defaults to require_all=True (AND logic).

You can now explicitly override this behavior whenever you need:

# User must have BOTH admin AND editor roles
@roles_required("admin", "editor", require_all=True)

# User must have ANY of the permissions (read OR write)
@permission_required("read", "write", require_all=False)

Additionally, while reviewing the code for this, I noticed that both of these decorators …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by ockan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants