8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-30 08:32:26 +00:00

Better error messages.

This commit is contained in:
Hugo Levy-Falk 2019-09-06 15:39:17 +02:00
parent 104d5b1d47
commit 04abc64cc9
2 changed files with 26 additions and 17 deletions

View file

@ -39,6 +39,10 @@ def can_view(user):
viewing is granted and msg is a message (can be None). viewing is granted and msg is a message (can be None).
""" """
can = user.has_module_perms('admin') can = user.has_module_perms('admin')
return can, None if can else _("You don't have the right to view this" return (
" application.") can,
None if can else _("You don't have the right to view this"
" application."),
'admin'
)

View file

@ -42,15 +42,9 @@ from re2o.utils import get_group_having_permission
def group_list(permissions): def group_list(permissions):
"""Create a string listing every groups having one of the given """Create a string listing every groups having one of the given
`permissions`.""" `permissions`."""
if permissions: return ", ".join([
return ", ".join([ g.name for g in get_group_having_permission(*permissions)
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 ""
def acl_base_decorator(method_name, *targets, on_instance=True): def acl_base_decorator(method_name, *targets, on_instance=True):
@ -169,12 +163,23 @@ ModelC)
for target, fields in group_targets(): for target, fields in group_targets():
for can, msg, permissions in process_target(target, fields): for can, msg, permissions in process_target(target, fields):
if not can: if not can:
error_messages.append( groups = group_list(permissions)
msg + _( if groups:
" You need to be a member of one of those" error_messages.append(
" groups : %s" msg + _(
) % group_list(permissions) " 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: if error_messages:
for msg in error_messages: for msg in error_messages:
messages.error( messages.error(