-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: custom permission for quiblet object
- Loading branch information
1 parent
5d41473
commit 45f43ac
Showing
3 changed files
with
32 additions
and
1 deletion.
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,16 @@ | ||
from rest_framework.permissions import SAFE_METHODS, BasePermission | ||
|
||
|
||
class IsRangerOrReadOnly(BasePermission): | ||
""" | ||
Custom permission to allow only rangers of a Quiblet to edit it. | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): # type: ignore | ||
if request.method in SAFE_METHODS: | ||
return True | ||
|
||
if request.user and request.user.is_authenticated: | ||
return obj.rangers.filter(id=request.user_profile.id).exists() | ||
else: | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework.permissions import SAFE_METHODS, BasePermission | ||
|
||
|
||
class IsQuibblerOrReadOnly(BasePermission): | ||
""" | ||
Custom permission to allow only quibbler of a feature to edit it. | ||
""" | ||
|
||
def has_object_permission(self, request, view, obj): | ||
if request.method in SAFE_METHODS: | ||
return True | ||
|
||
return obj.quibbler == request.user_profile |