8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 12:23: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):
""" Returns True if the user can change the 'controlled' status of
this invoice """
return (
user_request.has_perm('cotisations.change_facture_control'),
_("You don't have the right to edit the \"controlled\" state.")
)
if user_request.has_perm('cotisations.change_facture_control'):
return True, None
else:
return False, _("You don't have the right to edit the \"controlled\" state.")
@staticmethod
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
message if the boolean is `False`.
"""
return (
self.available_for_everyone
or user.has_perm('cotisations.buy_every_article')
or user.has_perm('cotisations.add_facture'),
_("You can't buy this article.")
)
if self.available_for_everyone or user.has_perm('cotisations.buy_every_article') or user.has_perm('cotisations.add_facture'):
return True, None
else:
return False, _("You can't buy this article.")
@classmethod
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
message if the boolean is `False`.
"""
return (
self.available_for_everyone
or user.has_perm('cotisations.use_every_payment')
or user.has_perm('cotisations.add_facture'),
_("You can't use this payment method.")
)
if self.available_for_everyone or user.has_perm('cotisations.use_every_payment') or user.has_perm('cotisations.add_facture'):
return True, None
else:
return False, _("You can't use this payment method.")
@classmethod
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
explanation message.
"""
return (user_request.has_perm('machines.change_machine_user'),
_("You don't have the right to change the machine's user."))
if user_request.has_perm('machines.change_machine_user'):
return True, None
else:
return False, _("You don't have the right to change the machine's user.")
@staticmethod
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):
"""Check if a user can change the machine associated with an
Interface object """
return (user_request.has_perm('machines.change_interface_machine'),
_("Permission required to edit the machine."))
if user_request.has_perm('machines.change_interface_machine'):
return True, None
else:
return False, _("Permission required to edit the machine.")
def can_edit(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour editer
@ -1350,9 +1354,10 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
@staticmethod
def can_change_slaac_ip(user_request, *_args, **_kwargs):
""" Check if a user can change the slaac value """
return (user_request.has_perm('machines.change_ipv6list_slaac_ip'),
_("Permission required to change the SLAAC value of an IPv6"
" address"))
if user_request.has_perm('machines.change_ipv6list_slaac_ip'):
return True, None
else:
return False, _("Permission required to change the SLAAC value of an IPv6 address")
def can_edit(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour editer