-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
105 additions
and
0 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,54 @@ | ||
from jet_bridge import settings | ||
from jet_bridge.utils.backend import project_auth | ||
|
||
|
||
class BasePermission(object): | ||
|
||
def has_permission(self, view): | ||
return True | ||
|
||
def has_object_permission(self, view, obj): | ||
return True | ||
|
||
|
||
class HasProjectPermissions(BasePermission): | ||
token_prefix = 'Token ' | ||
project_token_prefix = 'ProjectToken ' | ||
|
||
def has_permission(self, view): | ||
token = view.request.headers.get('Authorization') | ||
permission = getattr(view, 'required_project_permission', None) | ||
|
||
if not token: | ||
return False | ||
|
||
if token[:len(self.token_prefix)] == self.token_prefix: | ||
token = token[len(self.token_prefix):] | ||
|
||
result = project_auth(token, permission) | ||
|
||
if result.get('warning'): | ||
view.headers['X-Application-Warning'] = result['warning'] | ||
|
||
return result['result'] | ||
elif token[:len(self.project_token_prefix)] == self.project_token_prefix: | ||
token = token[len(self.project_token_prefix):] | ||
|
||
result = project_auth(token, permission) | ||
|
||
if result.get('warning'): | ||
view.headers['X-Application-Warning'] = result['warning'] | ||
|
||
return result['result'] | ||
else: | ||
return False | ||
|
||
|
||
class ModifyNotInDemo(BasePermission): | ||
|
||
def has_permission(self, view): | ||
if not settings.READ_ONLY: | ||
return True | ||
if view.action in ['create', 'update', 'partial_update', 'destroy']: | ||
return False | ||
return True |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
from jet_bridge.permissions import HasProjectPermissions | ||
from jet_bridge.views.base.api import APIView | ||
|
||
|
||
class MessageHandler(APIView): | ||
permission_classes = (HasProjectPermissions,) | ||
|
||
def post(self): | ||
pass |
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