8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-24 16:03:47 +00:00

Do not display unnecessary warnings.

This commit is contained in:
Hugo Levy-Falk 2019-09-09 14:40:40 +02:00 committed by chirac
parent a9ebe331dd
commit 8df5a05d89
5 changed files with 73 additions and 50 deletions

View file

@ -246,9 +246,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 """
can = user_request.has_perm('cotisations.change_facture_control')
return ( return (
user_request.has_perm('cotisations.change_facture_control'), 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',) ('cotisations.change_facture_control',)
) )
@ -746,11 +747,12 @@ 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`.
""" """
can = self.available_for_everyone \
or user.has_perm('cotisations.buy_every_article') \
or user.has_perm('cotisations.add_facture')
return ( return (
self.available_for_everyone can,
or user.has_perm('cotisations.buy_every_article') _("You can't buy this article.") if not can else None,
or user.has_perm('cotisations.add_facture'),
_("You can't buy this article."),
('cotisations.buy_every_article', 'cotisations.add_facture') ('cotisations.buy_every_article', 'cotisations.add_facture')
) )
@ -902,11 +904,12 @@ 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`.
""" """
can = self.available_for_everyone \
or user.has_perm('cotisations.use_every_payment') \
or user.has_perm('cotisations.add_facture')
return ( return (
self.available_for_everyone can,
or user.has_perm('cotisations.use_every_payment') _("You can't use this payment method.") if not can else None,
or user.has_perm('cotisations.add_facture'),
_("You can't use this payment method."),
('cotisations.use_every_payment', 'cotisations.add_facture') ('cotisations.use_every_payment', 'cotisations.add_facture')
) )

View file

@ -105,9 +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.
""" """
can = user_request.has_perm('machines.change_machine_user')
return ( return (
user_request.has_perm('machines.change_machine_user'), can,
_("You don't have the right to change the machine's user."), _("You don't have the right to change the machine's user.") if not can else None,
('machines.change_machine_user',) ('machines.change_machine_user',)
) )
@ -803,9 +804,10 @@ class Extension(RevMixin, AclMixin, models.Model):
restrictions restrictions
:param user_request: instance user qui fait l'edition :param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant""" :return: True ou False avec la raison de l'échec le cas échéant"""
can = user_request.has_perm('machines.use_all_extension')
return ( return (
user_request.has_perm('machines.use_all_extension'), can,
_("You cannot use all extensions."), _("You cannot use all extensions.") if not can else None,
('machines.use_all_extension',) ('machines.use_all_extension',)
) )
@ -1294,9 +1296,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 """
can = user_request.has_perm('machines.change_interface_machine')
return ( return (
user_request.has_perm('machines.change_interface_machine'), can,
_("Permission required to edit the machine."), _("Permission required to edit the machine.") if not can else None,
('machines.change_interface_machine',) ('machines.change_interface_machine',)
) )
@ -1421,10 +1424,11 @@ 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 """
can = user_request.has_perm('machines.change_ipv6list_slaac_ip')
return ( return (
user_request.has_perm('machines.change_ipv6list_slaac_ip'), can,
_("Permission required to change the SLAAC value of an IPv6" _("Permission required to change the SLAAC value of an IPv6"
" address"), " address") if not can else None,
('machines.change_ipv6list_slaac_ip',) ('machines.change_ipv6list_slaac_ip',)
) )

View file

@ -105,10 +105,11 @@ class AclMixin(object):
:param user_request: instance utilisateur qui fait la requête :param user_request: instance utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec""" :return: soit True, soit False avec la raison de l'échec"""
permission = cls.get_modulename() + '.add_' + cls.get_classname() permission = cls.get_modulename() + '.add_' + cls.get_classname()
can = user_request.has_perm(permission)
return ( return (
user_request.has_perm(permission), can,
_("You don't have the right to create a %s object.") _("You don't have the right to create a %s object.")
% cls.get_classname(), % cls.get_classname() if not can else None,
(permission,) (permission,)
) )
@ -119,10 +120,11 @@ class AclMixin(object):
:param user_request: Utilisateur qui fait la requête :param user_request: Utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec""" :return: soit True, soit False avec la raison de l'échec"""
permission = self.get_modulename() + '.change_' + self.get_classname() permission = self.get_modulename() + '.change_' + self.get_classname()
can = user_request.has_perm(permission)
return ( return (
user_request.has_perm(permission), can,
_("You don't have the right to edit a %s object.") _("You don't have the right to edit a %s object.")
% self.get_classname(), % self.get_classname() if not can else None,
(permission,) (permission,)
) )
@ -133,10 +135,11 @@ class AclMixin(object):
:param user_request: Utilisateur qui fait la requête :param user_request: Utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec""" :return: soit True, soit False avec la raison de l'échec"""
permission = self.get_modulename() + '.delete_' + self.get_classname() permission = self.get_modulename() + '.delete_' + self.get_classname()
can = user_request.has_perm(permission)
return ( return (
user_request.has_perm(permission), can,
_("You don't have the right to delete a %s object.") _("You don't have the right to delete a %s object.")
% self.get_classname(), % self.get_classname() if not can else None,
(permission,) (permission,)
) )
@ -147,10 +150,11 @@ class AclMixin(object):
:param user_request: instance user qui fait l'edition :param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant""" :return: True ou False avec la raison de l'échec le cas échéant"""
permission = cls.get_modulename() + '.view_' + cls.get_classname() permission = cls.get_modulename() + '.view_' + cls.get_classname()
can = user_request.has_perm(permission)
return ( return (
user_request.has_perm(permission), can,
_("You don't have the right to view every %s object.") _("You don't have the right to view every %s object.")
% cls.get_classname(), % cls.get_classname() if not can else None,
(permission,) (permission,)
) )
@ -161,10 +165,11 @@ class AclMixin(object):
:param user_request: instance user qui fait l'edition :param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant""" :return: True ou False avec la raison de l'échec le cas échéant"""
permission = self.get_modulename() + '.view_' + self.get_classname() permission = self.get_modulename() + '.view_' + self.get_classname()
can = user_request.has_perm(permission)
return ( return (
user_request.has_perm(permission), can,
_("You don't have the right to view a %s object.") _("You don't have the right to view a %s object.")
% self.get_classname(), % self.get_classname() if not can else None,
(permission,) (permission,)
) )

View file

@ -86,9 +86,10 @@ class Ticket(AclMixin, models.Model):
@staticmethod @staticmethod
def can_view_all(user_request, *_args, **_kwargs): def can_view_all(user_request, *_args, **_kwargs):
""" Check that the user has access to the list of all tickets""" """ Check that the user has access to the list of all tickets"""
can = user_request.has_perm('tickets.view_tickets')
return( return(
user_request.has_perm('tickets.view_tickets'), can,
_("You don't have the right to view the list of tickets."), _("You don't have the right to view the list of tickets.") if not can else None,
('tickets.view_tickets',) ('tickets.view_tickets',)
) )

View file

@ -968,9 +968,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:returns: a message and a boolean which is True if the user has :returns: a message and a boolean which is True if the user has
the right to change a state the right to change a state
""" """
can = user_request.has_perm('users.change_user_state')
return ( return (
user_request.has_perm('users.change_user_state'), can,
_("Permission required to change the state."), _("Permission required to change the state.") if not can else None,
('users.change_user_state',) ('users.change_user_state',)
) )
@ -999,9 +1000,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:returns: a message and a boolean which is True if the user has :returns: a message and a boolean which is True if the user has
the right to change a redirection the right to change a redirection
""" """
can = OptionalUser.get_cached_value('local_email_accounts_enabled')
return ( return (
OptionalUser.get_cached_value('local_email_accounts_enabled'), can,
_("Local email accounts must be enabled."), _("Local email accounts must be enabled.") if not can else None,
None None
) )
@ -1013,9 +1015,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:returns: a message and a boolean which is True if the user has :returns: a message and a boolean which is True if the user has
the right to change internal address the right to change internal address
""" """
can = OptionalUser.get_cached_value('local_email_accounts_enabled')
return ( return (
OptionalUser.get_cached_value('local_email_accounts_enabled'), can,
_("Local email accounts must be enabled."), _("Local email accounts must be enabled.") if not can else None,
None None
) )
@ -1027,9 +1030,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:returns: a message and a boolean which is True if the user has :returns: a message and a boolean which is True if the user has
the right to change a force the right to change a force
""" """
can = user_request.has_perm('users.change_user_force')
return ( return (
user_request.has_perm('users.change_user_force'), can,
_("Permission required to force the move."), _("Permission required to force the move.") if not can else None,
('users.change_user_force',) ('users.change_user_force',)
) )
@ -1041,9 +1045,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:returns: a message and a boolean which is True if the user has :returns: a message and a boolean which is True if the user has
the right to change a group the right to change a group
""" """
can = user_request.has_perm('users.change_user_grou')
return ( return (
user_request.has_perm('users.change_user_groups'), can,
_("Permission required to edit the user's groups of rights."), _("Permission required to edit the user's groups of rights.") if not can else None,
('users.change_user_groups') ('users.change_user_groups')
) )
@ -1054,9 +1059,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:param user_request: The user who request :param user_request: The user who request
:returns: a message and a boolean which is True if permission is granted. :returns: a message and a boolean which is True if permission is granted.
""" """
can = user_request.is_superuser
return ( return (
user_request.is_superuser, can,
_("'superuser' right required to edit the superuser flag."), _("'superuser' right required to edit the superuser flag.") if not can else None,
[] []
) )
@ -1099,9 +1105,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:return: True if the user can view the list and an explanation :return: True if the user can view the list and an explanation
message. message.
""" """
can = user_request.has_perm('use.view_user')
return ( return (
user_request.has_perm('users.view_user'), can,
_("You don't have the right to view the list of users."), _("You don't have the right to view the list of users.") if not can else None,
('users.view_user',) ('users.view_user',)
) )
@ -1113,9 +1120,10 @@ class User(RevMixin, FieldPermissionModelMixin, AbstractBaseUser,
:return: True if user_request has the right 'bureau', and a :return: True if user_request has the right 'bureau', and a
message. message.
""" """
can = user_request.has_perm('users.delete_user')
return ( return (
user_request.has_perm('users.delete_user'), can,
_("You don't have the right to delete this user."), _("You don't have the right to delete this user.") if not can else None,
('users.delete_user',) ('users.delete_user',)
) )
@ -1209,9 +1217,10 @@ class Adherent(User):
OptionalUser.get_cached_value('self_adhesion')): OptionalUser.get_cached_value('self_adhesion')):
return True, None, None return True, None, None
else: else:
can = user_request.has_perm('users.add_user')
return ( return (
user_request.has_perm('users.add_user'), can,
_("You don't have the right to create a user."), _("You don't have the right to create a user.") if not can else None,
('users.add_user',) ('users.add_user',)
) )
@ -1265,9 +1274,10 @@ class Club(User):
if OptionalUser.get_cached_value('all_can_create_club'): if OptionalUser.get_cached_value('all_can_create_club'):
return True, None, None return True, None, None
else: else:
can = user_request.has_perm('users.add_user')
return ( return (
user_request.has_perm('users.add_user'), can,
_("You don't have the right to create a club."), _("You don't have the right to create a club.") if not can else None,
('users.add_user',) ('users.add_user',)
) )