Last active
December 16, 2015 00:39
-
-
Save johngag/5349715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Roles Dictionary Values Example (1,2,4,8,16,32...) Up to 32 values | |
roles = {"addUsers": 1, "updatePermissions": 2, "uploadAttachments": 4, "createPosts": 8} | |
# Check if permission 9 has updatePermissions | |
# bitand will return 0 if False and a number if True | |
>>> 9&roles['updatePermissions'] | |
0 | |
# Check if permission 9 has addUsers | |
>>> 9&roles['addUsers'] | |
1 | |
# Check if permission 6 has addUsers | |
>>> 6&roles['addUsers'] | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment