add permissions backend
This commit is contained in:
parent
dcadc324db
commit
4c7e906c1a
2 changed files with 32 additions and 0 deletions
27
issue/backends.py
Normal file
27
issue/backends.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from django.contrib.auth.backends import ModelBackend
|
||||
|
||||
from issue.models import *
|
||||
|
||||
|
||||
def user_has_perm(user, perm, perms):
|
||||
for p in perms:
|
||||
# this permission allow that action and the user is concerned by this permission
|
||||
if hasattr(p, perm) and getattr(p, perm) and p.granted_to(user):
|
||||
return True
|
||||
|
||||
class ProjectBackend(ModelBackend):
|
||||
|
||||
def has_perm(self, user, perm, obj=None):
|
||||
|
||||
if isinstance(obj, Project):
|
||||
# get permissions concerning this project
|
||||
perms = obj.permissions.all()
|
||||
if user_has_perm(user, perm, perms):
|
||||
return True
|
||||
|
||||
# get global permissions
|
||||
perms = GlobalPermission.objects.all()
|
||||
if user_has_perm(user, perm, perms):
|
||||
return True
|
||||
|
||||
return False
|
|
@ -111,4 +111,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
|
|||
'issue.context_processors.projects',
|
||||
)
|
||||
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'django.contrib.auth.backends.ModelBackend',
|
||||
'issue.backends.ProjectBackend',
|
||||
)
|
||||
|
||||
SITE_ID = 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue