-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added authorization middleware
- Loading branch information
Showing
6 changed files
with
43 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SUPER_USER_ROLE = "super_user" | ||
MEMBER_ROLE = "member" |
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 |
---|---|---|
@@ -1,6 +1,19 @@ | ||
from rest_framework import permissions | ||
from apps.base.constants import SUPER_USER_ROLE, MEMBER_ROLE | ||
|
||
|
||
class IsSuperUserPermission(permissions.BasePermission): | ||
def has_permission(self, request, view): | ||
return False | ||
def AuthorizationPermissions(roles=[]): | ||
class AuthorizationPermission: | ||
def has_permission(self, request, view): | ||
if not request.user.is_authenticated: | ||
return False | ||
|
||
user_roles = request.user.roles | ||
for role in roles: | ||
if user_roles.get(role, False) is False: | ||
return False | ||
else: | ||
continue | ||
return True | ||
|
||
return AuthorizationPermission |
This file was deleted.
Oops, something went wrong.
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