From 5ee0f05193999865fb9131f9111f3f55068761c3 Mon Sep 17 00:00:00 2001 From: detraz Date: Mon, 18 Mar 2019 00:05:02 +0100 Subject: [PATCH] Warning message with acl --- re2o/acl.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/re2o/acl.py b/re2o/acl.py index 116d273b..13413853 100644 --- a/re2o/acl.py +++ b/re2o/acl.py @@ -148,20 +148,19 @@ ModelC) can_change_fct = getattr(target, 'can_change_' + field) yield can_change_fct(request.user, *args, **kwargs) - error_messages = [ - x[1] for x in chain.from_iterable( - process_target(x[0], x[1]) for x in group_targets() - ) if not x[0] - ] - if error_messages: - for msg in error_messages: + for accept, msg in chain.from_iterable(process_target(x[0], x[1]) for x in group_targets()): + if not accept: messages.error( request, msg or _("You don't have the right to access" - " this menu.")) - return redirect(reverse( - 'users:profil', - kwargs={'userid': str(request.user.id)} - )) + " this menu.") + ) + return redirect(reverse( + 'users:profil', + kwargs={'userid': str(request.user.id)} + )) + elif msg: + messages.warning(request, msg) + return view(request, *chain(instances, args), **kwargs) return wrapper return decorator