fix permission for companies

This commit is contained in:
Pierre Brunet 2017-02-05 15:50:42 +01:00
parent b3c2c79975
commit 346e07f0a8

View File

@ -45,6 +45,32 @@ class Company(models.Model):
class Meta: class Meta:
verbose_name = _("company") verbose_name = _("company")
def is_owned_by(self, user):
"""
Method to see if that object can be edited by the given user
"""
if user.is_in_group(settings.SITH_GROUP_ACCOUNTING_ADMIN_ID):
return True
return False
def can_be_edited_by(self, user):
"""
Method to see if that object can be edited by the given user
"""
for club in user.memberships.filter(end_date=None).all():
if club and club.role == 7:
return True
return False
def can_be_viewed_by(self, user):
"""
Method to see if that object can be viewed by the given user
"""
for club in user.memberships.filter(end_date=None).all():
if club and club.role >= 7:
return True
return False
def get_absolute_url(self): def get_absolute_url(self):
return reverse('accounting:co_edit', kwargs={'co_id': self.id}) return reverse('accounting:co_edit', kwargs={'co_id': self.id})