8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Avoid failing when permissions depending on another model are None.

This commit is contained in:
Hugo Levy-Falk 2020-04-30 22:32:17 +02:00 committed by Gabriel Detraz
parent 2d40c3ecaa
commit 2a7d334db7
2 changed files with 14 additions and 14 deletions

View file

@ -138,7 +138,7 @@ class Facture(BaseInvoice):
abstract = False
permissions = (
# TODO : change facture to invoice
("change_facture_control", _("Can edit the \"controlled\" state")),
("change_facture_control", _('Can edit the "controlled" state')),
("view_facture", _("Can view an invoice object")),
("change_all_facture", _("Can edit all the previous invoices")),
)
@ -166,7 +166,7 @@ class Facture(BaseInvoice):
return (
False,
_("You don't have the right to edit this user's invoices."),
("cotisations.change_all_facture",) + permissions,
("cotisations.change_all_facture",) + (permissions or ()),
)
elif not user_request.has_perm("cotisations.change_all_facture") and (
self.control or not self.valid
@ -198,7 +198,7 @@ class Facture(BaseInvoice):
return (
False,
_("You don't have the right to delete this user's invoices."),
("cotisations.change_all_facture",) + permissions,
("cotisations.change_all_facture",) + (permissions or ()),
)
elif not user_request.has_perm("cotisations.change_all_facture") and (
self.control or not self.valid
@ -243,7 +243,7 @@ class Facture(BaseInvoice):
can = user_request.has_perm("cotisations.change_facture_control")
return (
can,
_("You don't have the right to edit the \"controlled\" state.")
_('You don\'t have the right to edit the "controlled" state.')
if not can
else None,
("cotisations.change_facture_control",),
@ -297,14 +297,14 @@ class Facture(BaseInvoice):
for purchase in self.vente_set.all():
if hasattr(purchase, "cotisation"):
cotisation = purchase.cotisation
if cotisation.type_cotisation == 'Connexion':
if cotisation.type_cotisation == "Connexion":
cotisation.date_start = date_con
date_con += relativedelta(
months=(purchase.duration or 0) * purchase.number,
days=(purchase.duration_days or 0) * purchase.number,
)
cotisation.date_end = date_con
elif cotisation.type_cotisation == 'Adhesion':
elif cotisation.type_cotisation == "Adhesion":
cotisation.date_start = date_adh
date_adh += relativedelta(
months=(purchase.duration or 0) * purchase.number,
@ -566,7 +566,7 @@ class Vente(RevMixin, AclMixin, models.Model):
return (
False,
_("You don't have the right to edit this user's purchases."),
("cotisations.change_all_facture",) + permissions,
("cotisations.change_all_facture",) + (permissions or ()),
)
elif not user_request.has_perm("cotisations.change_all_vente") and (
self.facture.control or not self.facture.valid

View file

@ -178,7 +178,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, AclMixin, models.Model):
return (
False,
_("You don't have the right to edit a machine of another" " user."),
("machines.change_interface",) + permissions,
("machines.change_interface",) + (permissions or ()),
)
return True, None, None
@ -199,7 +199,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, AclMixin, models.Model):
"You don't have the right to delete a machine"
" of another user."
),
("machines.delete_interface",) + permissions,
("machines.change_interface",) + (permissions or ()),
)
return True, None, None
@ -1344,7 +1344,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
return (
False,
_("You don't have the right to edit a machine of another" " user."),
("machines.change_interface",) + permissions,
("machines.change_interface",) + (permissions or ()),
)
return True, None, None
@ -1362,7 +1362,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
return (
False,
_("You don't have the right to edit a machine of another" " user."),
("machines.change_interface",) + permissions,
("machines.change_interface",) + (permissions or ()),
)
return True, None, None
@ -1481,8 +1481,8 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
if not (user_request.has_perm("machines.delete_ipv6list") and can_user):
return (
False,
_("You don't have the right to delete ipv6 of a machine of another user."),
("machines.delete_ipv6list",) + permissions,
_("You don't have the right to edit a machine of another user."),
("machines.change_ipv6list",) + (permissions or ()),
)
return True, None, None