From 592b96912960d16d0f554d39e3e195036213092d Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Fri, 6 Sep 2019 15:27:03 +0200 Subject: [PATCH] Helpful acl messages for default mixin. --- re2o/mixins.py | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/re2o/mixins.py b/re2o/mixins.py index f3858428..9d7f7b2f 100644 --- a/re2o/mixins.py +++ b/re2o/mixins.py @@ -104,12 +104,12 @@ class AclMixin(object): un object :param user_request: instance utilisateur qui fait la requête :return: soit True, soit False avec la raison de l'échec""" + permission = cls.get_modulename() + '.add_' + cls.get_classname() return ( - user_request.has_perm( - cls.get_modulename() + '.add_' + cls.get_classname() - ), - (_("You don't have the right to create a %s object.") - % cls.get_classname()) + user_request.has_perm(permission), + _("You don't have the right to create a %s object.") + % cls.get_classname(), + (permission,) ) def can_edit(self, user_request, *_args, **_kwargs): @@ -118,12 +118,12 @@ class AclMixin(object): :param self: Instance à editer :param user_request: Utilisateur qui fait la requête :return: soit True, soit False avec la raison de l'échec""" + permission = self.get_modulename() + '.change_' + self.get_classname() return ( - user_request.has_perm( - self.get_modulename() + '.change_' + self.get_classname() - ), - (_("You don't have the right to edit a %s object.") - % self.get_classname()) + user_request.has_perm(permission), + _("You don't have the right to edit a %s object.") + % self.get_classname(), + (permission,) ) def can_delete(self, user_request, *_args, **_kwargs): @@ -132,12 +132,12 @@ class AclMixin(object): :param self: Instance à delete :param user_request: Utilisateur qui fait la requête :return: soit True, soit False avec la raison de l'échec""" + permission = self.get_modulename() + '.delete_' + self.get_classname() return ( - user_request.has_perm( - self.get_modulename() + '.delete_' + self.get_classname() - ), - (_("You don't have the right to delete a %s object.") - % self.get_classname()) + user_request.has_perm(permission), + _("You don't have the right to delete a %s object.") + % self.get_classname(), + (permission,) ) @classmethod @@ -146,12 +146,12 @@ class AclMixin(object): droit particulier view objet correspondant :param user_request: instance user qui fait l'edition :return: True ou False avec la raison de l'échec le cas échéant""" + permission = cls.get_modulename() + '.view_' + cls.get_classname() return ( - user_request.has_perm( - cls.get_modulename() + '.view_' + cls.get_classname() - ), - (_("You don't have the right to view every %s object.") - % cls.get_classname()) + user_request.has_perm(permission), + _("You don't have the right to view every %s object.") + % cls.get_classname(), + (permission,) ) def can_view(self, user_request, *_args, **_kwargs): @@ -160,11 +160,11 @@ class AclMixin(object): :param self: instance à voir :param user_request: instance user qui fait l'edition :return: True ou False avec la raison de l'échec le cas échéant""" + permission = self.get_modulename() + '.view_' + self.get_classname() return ( - user_request.has_perm( - self.get_modulename() + '.view_' + self.get_classname() - ), - (_("You don't have the right to view a %s object.") - % self.get_classname()) + user_request.has_perm(permission), + _("You don't have the right to view a %s object.") + % self.get_classname(), + (permission,) )