play with somort of permission management
This commit is contained in:
@@ -1 +1,11 @@
|
||||
from .middleware.current_user import get_current_user
|
||||
from .middleware.current_user import get_current_user, get_current_request
|
||||
|
||||
def permissions(instance, read = False):
|
||||
if read:
|
||||
return True
|
||||
u = get_current_user()
|
||||
if u.is_superuser or u == instance.author:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
20
lib/mixins/__init__.py
Normal file
20
lib/mixins/__init__.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from lib import permissions
|
||||
|
||||
|
||||
class PermissionsAdminMixin:
|
||||
def has_add_permission(self, request, obj=None):
|
||||
"""If a group right is not set :)
|
||||
Allways be able to create a version
|
||||
"""
|
||||
return permissions(obj) if obj else True
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
"""Versions are immutable """
|
||||
return permissions(obj) if obj else True
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
"""Versions are immutable """
|
||||
return permissions(obj) if obj else True
|
||||
|
||||
def has_view_permissions(selfself, request, obj=None):
|
||||
return True
|
||||
Reference in New Issue
Block a user