From 04abc64cc973f2b2534282decb2bb292602c2098 Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Fri, 6 Sep 2019 15:39:17 +0200 Subject: [PATCH] Better error messages. --- logs/acl.py | 8 ++++++-- re2o/acl.py | 35 ++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/logs/acl.py b/logs/acl.py index ee9a7b1b..b4df34af 100644 --- a/logs/acl.py +++ b/logs/acl.py @@ -39,6 +39,10 @@ def can_view(user): viewing is granted and msg is a message (can be None). """ can = user.has_module_perms('admin') - return can, None if can else _("You don't have the right to view this" - " application.") + return ( + can, + None if can else _("You don't have the right to view this" + " application."), + 'admin' + ) diff --git a/re2o/acl.py b/re2o/acl.py index 5d3601b4..23f51210 100644 --- a/re2o/acl.py +++ b/re2o/acl.py @@ -42,15 +42,9 @@ from re2o.utils import get_group_having_permission def group_list(permissions): """Create a string listing every groups having one of the given `permissions`.""" - if permissions: - return ", ".join([ - g.name for g in get_group_having_permission(*permissions) - ]) or "No group have the %s permission(s) !" % " or ".join([ - ",".join(permissions[:-1]), - permissions[-1]] if len(permissions) > 2 else permissions - ) - else: - return "" + return ", ".join([ + g.name for g in get_group_having_permission(*permissions) + ]) def acl_base_decorator(method_name, *targets, on_instance=True): @@ -169,12 +163,23 @@ ModelC) for target, fields in group_targets(): for can, msg, permissions in process_target(target, fields): if not can: - error_messages.append( - msg + _( - " You need to be a member of one of those" - " groups : %s" - ) % group_list(permissions) - ) + groups = group_list(permissions) + if groups: + error_messages.append( + msg + _( + " You need to be a member of one of those" + " groups : %s" + ) % groups + ) + else: + error_messages.append( + msg + " No group have the %s permission(s) !" \ + % " or ".join([ + ",".join(permissions[:-1]), + permissions[-1]] + if len(permissions) > 2 else permissions + ) + ) if error_messages: for msg in error_messages: messages.error(