-
Notifications
You must be signed in to change notification settings - Fork 10
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
Jon Walz
authored and
Jon Walz
committed
Feb 14, 2024
1 parent
fb7c73b
commit 63cbfa5
Showing
6 changed files
with
35 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
class SessionUserIsAccountOwner(): #Add appropriate base class | ||
|
||
def get_user_uri_for_view(self, view): | ||
raise NotImplementedError('Subclass must implement this') | ||
|
||
def has_object_permission(self, request, view, obj): | ||
session_user_uri = request.session.get('user_reference_uri') | ||
return session_user_uri == obj.account_owner.uri | ||
|
||
|
||
class IsAuthenticated: | ||
|
||
def has_permission(self, request, view): | ||
return request.session.get('user_reference_uri') is not 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from rest_framework_json_api.views import ReadOnlyViewSet | ||
from rest_framework_json_api.views import ReadOnlyModelViewSet | ||
|
||
from .models import ExternalStorageService | ||
from .serializers import ExternalStorageServiceSerializer | ||
|
||
|
||
class ExternalStorageServiceViewSet(ReadOnlyViewSet): | ||
class ExternalStorageServiceViewSet(ReadOnlyModelViewSet): | ||
queryset = ExternalStorageService.objects.all() | ||
serializer_class = ExternalStorageServiceSerializer | ||
# TODO: permissions_classes |
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,9 +1,11 @@ | ||
from .models import UserReference | ||
from .serializers import UserReferenceSerializer | ||
|
||
from addon_service.common.permissions import SessionUserIsAccountOwner | ||
from addon_service.common.viewsets import RetrieveOnlyViewSet | ||
|
||
|
||
class UserReferenceViewSet(RetrieveOnlyViewSet): | ||
queryset = UserReference.objects.all() | ||
serializer_class = UserReferenceSerializer | ||
# TODO: permissions_classes | ||
permissions = [SessionUserIsAccountOwner] |