-
-
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.
- Loading branch information
Showing
4 changed files
with
564 additions
and
19 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 |
---|---|---|
@@ -1,29 +1,45 @@ | ||
from rest_framework import permissions | ||
|
||
from bothub.common.models import Repository | ||
from .. import READ_METHODS | ||
from .. import WRITE_METHODS | ||
|
||
|
||
class RepositoryEvaluatePermission(permissions.BasePermission): | ||
|
||
def has_object_permission(self, request, view, obj): | ||
authorization = obj.repository_update. \ | ||
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 | ||
def has_permission(self, request, view): | ||
try: | ||
repository = Repository.objects.get( | ||
uuid=request.GET.get('repository_uuid') | ||
) | ||
authorization = repository.get_user_authorization(request.user) | ||
|
||
if request.method in READ_METHODS and \ | ||
not request.user.is_authenticated: | ||
return authorization.can_read | ||
|
||
if request.user.is_authenticated: | ||
if request.method in READ_METHODS: | ||
return authorization.can_read | ||
if request.method in WRITE_METHODS: | ||
return authorization.can_write | ||
return authorization.is_admin | ||
return False | ||
except Repository.DoesNotExist: | ||
return False | ||
|
||
class RepositoryEvaluateResultPermission(permissions.BasePermission): | ||
|
||
def has_object_permission(self, request, view, obj): | ||
authorization = obj.repository_update. \ | ||
repository.get_user_authorization(request.user) | ||
class RepositoryEvaluateResultPermission(permissions.BasePermission): | ||
|
||
if request.method in READ_METHODS: | ||
return authorization.can_read | ||
return authorization.can_contribute | ||
def has_permission(self, request, view): | ||
try: | ||
repository = Repository.objects.get( | ||
uuid=request.GET.get('repository_uuid') | ||
) | ||
authorization = repository.get_user_authorization(request.user) | ||
|
||
if request.method in READ_METHODS: | ||
return authorization.can_read | ||
return authorization.can_contribute | ||
except Repository.DoesNotExist: | ||
return False |
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
Oops, something went wrong.