Improve right handling for accounting

This commit is contained in:
Skia
2016-05-09 11:49:01 +02:00
parent 39661b8de7
commit 27805640a1
11 changed files with 240 additions and 60 deletions

View File

@ -207,14 +207,12 @@ class User(AbstractBaseUser, PermissionsMixin):
"""
Determine if the object is owned by the user
"""
if not hasattr(obj, "owner_group"):
return False
if (self.is_superuser or self.is_in_group(obj.owner_group.name) or
self.has_perm(obj.__class__.__module__.split('.')[0]+".change_prop_"+obj.__class__.__name__.lower()) or
self.groups.filter(id=settings.SITH_GROUPS['root']['id']).exists()):
return True
if hasattr(obj, "is_owned_by") and obj.is_owned_by(self):
return True
if hasattr(obj, "owner_group") and self.is_in_group(obj.owner_group.name):
return False
if self.is_superuser or self.is_in_group(settings.SITH_GROUPS['root']['name']):
return True
return False
def can_edit(self, obj):
@ -231,8 +229,6 @@ class User(AbstractBaseUser, PermissionsMixin):
return True
if hasattr(obj, "can_be_edited_by") and obj.can_be_edited_by(self):
return True
if self.has_perm(obj.__class__.__module__.split('.')[0]+".change_"+obj.__class__.__name__.lower()):
return True
return False
def can_view(self, obj):
@ -247,8 +243,6 @@ class User(AbstractBaseUser, PermissionsMixin):
return True
if hasattr(obj, "can_be_viewed_by") and obj.can_be_viewed_by(self):
return True
if self.has_perm(obj.__class__.__module__.split('.')[0]+".view_"+obj.__class__.__name__.lower()):
return True
return False
def can_be_edited_by(self, user):