8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 20:33:11 +00:00

new acl style in machines and cotisations

This commit is contained in:
detraz 2019-03-18 00:13:46 +01:00
parent 5ee0f05193
commit 1e80a6880d
2 changed files with 24 additions and 23 deletions

View file

@ -212,10 +212,10 @@ class Facture(BaseInvoice):
def can_change_control(user_request, *_args, **_kwargs): def can_change_control(user_request, *_args, **_kwargs):
""" Returns True if the user can change the 'controlled' status of """ Returns True if the user can change the 'controlled' status of
this invoice """ this invoice """
return ( if user_request.has_perm('cotisations.change_facture_control'):
user_request.has_perm('cotisations.change_facture_control'), return True, None
_("You don't have the right to edit the \"controlled\" state.") else:
) return False, _("You don't have the right to edit the \"controlled\" state.")
@staticmethod @staticmethod
def can_create(user_request, *_args, **_kwargs): def can_create(user_request, *_args, **_kwargs):
@ -679,12 +679,10 @@ class Article(RevMixin, AclMixin, models.Model):
A boolean stating if usage is granted and an explanation A boolean stating if usage is granted and an explanation
message if the boolean is `False`. message if the boolean is `False`.
""" """
return ( if self.available_for_everyone or user.has_perm('cotisations.buy_every_article') or user.has_perm('cotisations.add_facture'):
self.available_for_everyone return True, None
or user.has_perm('cotisations.buy_every_article') else:
or user.has_perm('cotisations.add_facture'), return False, _("You can't buy this article.")
_("You can't buy this article.")
)
@classmethod @classmethod
def find_allowed_articles(cls, user, target_user): def find_allowed_articles(cls, user, target_user):
@ -834,12 +832,10 @@ class Paiement(RevMixin, AclMixin, models.Model):
A boolean stating if usage is granted and an explanation A boolean stating if usage is granted and an explanation
message if the boolean is `False`. message if the boolean is `False`.
""" """
return ( if self.available_for_everyone or user.has_perm('cotisations.use_every_payment') or user.has_perm('cotisations.add_facture'):
self.available_for_everyone return True, None
or user.has_perm('cotisations.use_every_payment') else:
or user.has_perm('cotisations.add_facture'), return False, _("You can't use this payment method.")
_("You can't use this payment method.")
)
@classmethod @classmethod
def find_allowed_payments(cls, user): def find_allowed_payments(cls, user):

View file

@ -105,8 +105,10 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
A tuple with a boolean stating if edition is allowed and an A tuple with a boolean stating if edition is allowed and an
explanation message. explanation message.
""" """
return (user_request.has_perm('machines.change_machine_user'), if user_request.has_perm('machines.change_machine_user'):
_("You don't have the right to change the machine's user.")) return True, None
else:
return False, _("You don't have the right to change the machine's user.")
@staticmethod @staticmethod
def can_view_all(user_request, *_args, **_kwargs): def can_view_all(user_request, *_args, **_kwargs):
@ -1245,8 +1247,10 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
def can_change_machine(user_request, *_args, **_kwargs): def can_change_machine(user_request, *_args, **_kwargs):
"""Check if a user can change the machine associated with an """Check if a user can change the machine associated with an
Interface object """ Interface object """
return (user_request.has_perm('machines.change_interface_machine'), if user_request.has_perm('machines.change_interface_machine'):
_("Permission required to edit the machine.")) return True, None
else:
return False, _("Permission required to edit the machine.")
def can_edit(self, user_request, *args, **kwargs): def can_edit(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour editer """Verifie que l'user a les bons droits infra pour editer
@ -1350,9 +1354,10 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
@staticmethod @staticmethod
def can_change_slaac_ip(user_request, *_args, **_kwargs): def can_change_slaac_ip(user_request, *_args, **_kwargs):
""" Check if a user can change the slaac value """ """ Check if a user can change the slaac value """
return (user_request.has_perm('machines.change_ipv6list_slaac_ip'), if user_request.has_perm('machines.change_ipv6list_slaac_ip'):
_("Permission required to change the SLAAC value of an IPv6" return True, None
" address")) else:
return False, _("Permission required to change the SLAAC value of an IPv6 address")
def can_edit(self, user_request, *args, **kwargs): def can_edit(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour editer """Verifie que l'user a les bons droits infra pour editer