-
Notifications
You must be signed in to change notification settings - Fork 706
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
5 changed files
with
52 additions
and
46 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 |
---|---|---|
@@ -1,33 +1,13 @@ | ||
|
||
from rest_framework.permissions import BasePermission, SAFE_METHODS | ||
|
||
|
||
class IsAdminOrIfAuthenticatedReadOnly(BasePermission): | ||
def has_permission(self, request, view): | ||
return bool( | ||
( | ||
request.method in SAFE_METHODS | ||
and request.user | ||
and request.user.is_authenticated | ||
request.method in SAFE_METHODS | ||
and request.user | ||
and request.user.is_authenticated | ||
) | ||
or (request.user and request.user.is_staff) | ||
) | ||
|
||
|
||
class IsAdminOrIfAuthenticatedListCreate(BasePermission): | ||
def has_permission(self, request, view): | ||
if request.method in ("GET", "HEAD", "OPTIONS"): | ||
return request.user and request.user.is_authenticated | ||
if request.method == "delete": | ||
return False | ||
return IsAdminOrIfAuthenticatedReadOnly | ||
|
||
def has_object_permission(self, request, view, obj): | ||
return False | ||
|
||
|
||
class IsAdminOrIfAuthenticatedCRUD(BasePermission): | ||
def has_permission(self, request, view): | ||
if view.action in ["list", "create", "update", "partial_update", "delete"]: | ||
return request.user and request.user.is_authenticated | ||
return IsAdminOrIfAuthenticatedReadOnly |
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 |
---|---|---|
|
@@ -21,6 +21,3 @@ def update(self, instance, validated_data): | |
user.save() | ||
|
||
return user | ||
|
||
|
||
|
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