mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-04 17:06:27 +00:00
Better error messages.
This commit is contained in:
parent
104d5b1d47
commit
04abc64cc9
2 changed files with 26 additions and 17 deletions
|
@ -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'
|
||||
)
|
||||
|
||||
|
|
21
re2o/acl.py
21
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 ""
|
||||
])
|
||||
|
||||
|
||||
def acl_base_decorator(method_name, *targets, on_instance=True):
|
||||
|
@ -169,11 +163,22 @@ ModelC)
|
|||
for target, fields in group_targets():
|
||||
for can, msg, permissions in process_target(target, fields):
|
||||
if not can:
|
||||
groups = group_list(permissions)
|
||||
if groups:
|
||||
error_messages.append(
|
||||
msg + _(
|
||||
" You need to be a member of one of those"
|
||||
" groups : %s"
|
||||
) % group_list(permissions)
|
||||
) % 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:
|
||||
|
|
Loading…
Reference in a new issue