Skip to content
Snippets Groups Projects
Commit 47cdc304 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[common][permissions] Implement permissions from various mixins

This will allow to remove mixins that where going special
permission management.

Removing these mixins will allow for more flexibility with
regard to permission management.
parent e34a2941
No related branches found
No related tags found
1 merge request!327Refactor update creation api
......@@ -50,3 +50,41 @@ class IsAuthor(permissions.IsAuthenticated):
author_name = kwargs.get("author_name")
allowed = request.user.username == author_name
return allowed
class IsAuthorOrReadOnly(IsAuthor):
"""
Either allow access if using a read method or
check that the user is also the author.
"""
def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return True
else:
return super().has_permission(request, view)
class IsAdminOrReadOnly(permissions.IsAdminUser):
"""
Either allow access if using a read method or
check that the user is an admin.
"""
def has_permission(self, request, view):
if request.method in permissions.SAFE_METHODS:
return True
else:
return super().has_permission(request, view)
class IsModifiableOrRead(permissions.BasePermission):
"""
Check for modifiable flag if there's a modification that is tried
"""
def has_object_permission(self, request, view, obj):
if request.method in permissions.SAFE_METHODS:
return True
else:
return obj.modifiable()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment