first commit for v0.2

This commit is contained in:
Élie Bouttier 2014-08-30 15:38:06 -07:00
parent 6ba03afc73
commit 1463854a45
143 changed files with 20775 additions and 2764 deletions

29
permissions/backends.py Normal file
View file

@ -0,0 +1,29 @@
from django.contrib.auth.backends import ModelBackend
from tracker.models import Project
from permissions.models import GlobalPermission
def user_has_perm(user, perm, perms):
for p in perms:
# this perm allow that action and the user is concerned by this perm
if hasattr(p, perm) and getattr(p, perm) and p.granted_to(user):
return True
class Backend(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