From 6b8b5764529507ef604f1d101a4437e4074d9e09 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 6 Mar 2018 16:31:02 +0100 Subject: [PATCH] Ajout du tag can_view_any_app et autorise de mettre plusieurs apps dans can_view_app --- re2o/templatetags/acl.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/re2o/templatetags/acl.py b/re2o/templatetags/acl.py index 28a7b4d3..c14fcbd6 100644 --- a/re2o/templatetags/acl.py +++ b/re2o/templatetags/acl.py @@ -180,13 +180,17 @@ def get_callback(tag_name, obj=None): if tag_name == 'cannot_view_all': return acl_fct(obj.can_view_all, True) if tag_name == 'can_view_app': - return acl_fct(sys.modules[obj].can_view, False) + return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), False) if tag_name == 'cannot_view_app': - return acl_fct(sys.modules[obj].can_view, True) + return acl_fct(lambda x : (not any(not sys.modules[o].can_view(x) for o in obj), None), True) if tag_name == 'can_edit_history': return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),False) if tag_name == 'cannot_edit_history': return acl_fct(lambda user:(user.has_perm('admin.change_logentry'),None),True) + if tag_name == 'can_view_any_app': + return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), False) + if tag_name == 'cannot_view_any_app': + return acl_fct(lambda x : (any(sys.modules[o].can_view(x) for o in obj), None), True) raise template.TemplateSyntaxError( "%r tag is not a valid can_xxx tag" % tag_name @@ -228,22 +232,25 @@ def acl_history_filter(parser, token): return AclNode(callback, oknodes, konodes) +@register.tag('can_view_any_app') +@register.tag('cannot_view_any_app') @register.tag('can_view_app') @register.tag('cannot_view_app') def acl_app_filter(parser, token): """Templatetag for acl checking on applications.""" try: - tag_name, app_name = token.split_contents() + tag_name, *app_name = token.split_contents() except ValueError: raise template.TemplateSyntaxError( - "%r tag require 1 argument : the application" + "%r tag require 1 argument : an application" % token.contents.split()[0] ) - if not app_name in sys.modules.keys(): - raise template.TemplateSyntaxError( - "%r is not a registered application for acl." - % app_name - ) + for name in app_name: + if not name in sys.modules.keys(): + raise template.TemplateSyntaxError( + "%r is not a registered application for acl." + % name + ) callback = get_callback(tag_name, app_name)