This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from josecoelho96/dev/roles
Add roles/permissions system
- Loading branch information
Showing
6 changed files
with
150 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import common | ||
import database | ||
import exceptions | ||
import logging as log | ||
|
||
common.setup_logger() | ||
|
||
class RoleLevels: | ||
Admin = "admin" | ||
Staff = "staff" | ||
|
||
role_level = { | ||
"admin": 50, | ||
"staff": 40 | ||
} | ||
|
||
def user_has_permission(level, user): | ||
""" Checks if a user has permissions to execute some operation.""" | ||
try: | ||
user_permission = database.get_user_permissions(user) | ||
except exceptions.QueryDatabaseError as ex: | ||
log.error("Could not perform user permissions check: {}".format(ex)) | ||
return False | ||
else: | ||
log.debug(user_permission) | ||
if not user_permission: | ||
log.error("User doesn't have any permission.") | ||
return False | ||
|
||
if role_level[user_permission] >= role_level[level]: | ||
log.debug("User has permission") | ||
return True | ||
else: | ||
log.error("User doesn't have enough permission.") | ||
return False |