-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ModuleHasPermission to check if the token given is from a admin u…
…ser at keycloak
- Loading branch information
1 parent
809a891
commit e18b8d9
Showing
5 changed files
with
19 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
from rest_framework import permissions | ||
|
||
from .. import READ_METHODS, WRITE_METHODS | ||
from bothub.utils import check_module_keycloak | ||
|
||
|
||
class RepositoryEntityGroupHasPermission(permissions.BasePermission): | ||
class ModuleHasPermission(permissions.BasePermission): | ||
def has_object_permission(self, request, view, obj): # pragma: no cover | ||
authorization = obj.repository_version.repository.get_user_authorization( | ||
request.user | ||
) | ||
if request.method in READ_METHODS: | ||
return authorization.can_read | ||
if request.user.is_authenticated: | ||
if request.method in WRITE_METHODS: | ||
return authorization.can_write | ||
return authorization.is_admin | ||
return False | ||
return check_module_keycloak(request.query_params.get("token", None)) |
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