mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 19:33:11 +00:00
AclModelNode → AclNode + création du templatetag can_edit_history.
This commit is contained in:
parent
78647cd768
commit
a084324c6e
1 changed files with 31 additions and 20 deletions
|
@ -149,7 +149,7 @@ def get_model(model_name):
|
|||
)
|
||||
|
||||
|
||||
def get_callback(tag_name, obj):
|
||||
def get_callback(tag_name, obj=None):
|
||||
"""Return the right function to call back to check for acl"""
|
||||
|
||||
if tag_name == 'can_create':
|
||||
|
@ -196,6 +196,10 @@ def get_callback(tag_name, obj):
|
|||
),
|
||||
True
|
||||
)
|
||||
if tag_name == 'can_edit_history':
|
||||
return acl_fct(lambda user:(user.has_perms(('admin',)),None),False)
|
||||
if tag_name == 'cannot_edit_history':
|
||||
return acl_fct(lambda user:(user.has_perms(('admin',)),None),True)
|
||||
|
||||
raise template.TemplateSyntaxError(
|
||||
"%r tag is not a valid can_xxx tag" % tag_name
|
||||
|
@ -216,6 +220,27 @@ def acl_fct(callback, reverse):
|
|||
|
||||
return acl_fct_reverse if reverse else acl_fct_normal
|
||||
|
||||
|
||||
@register.tag('can_edit_history')
|
||||
@register.tag('cannot_edit_history')
|
||||
def acl_history_filter(parser, token):
|
||||
"""Templatetag for acl checking on history."""
|
||||
tag_name,_ = token.split_contents()
|
||||
|
||||
callback = get_callback(tag_name)
|
||||
oknodes = parser.parse(('acl_else', 'acl_end'))
|
||||
token = parser.next_token()
|
||||
if token.contents == 'acl_else':
|
||||
konodes = parser.parse(('acl_end'))
|
||||
token = parser.next_token()
|
||||
else:
|
||||
konodes = NodeList()
|
||||
|
||||
assert token.contents == 'acl_end'
|
||||
|
||||
return AclNode(callback, oknodes, konodes)
|
||||
|
||||
|
||||
@register.tag('can_view_app')
|
||||
@register.tag('cannot_view_app')
|
||||
def acl_app_filter(parser, token):
|
||||
|
@ -245,7 +270,7 @@ def acl_app_filter(parser, token):
|
|||
|
||||
assert token.contents == 'acl_end'
|
||||
|
||||
return AclAppNode(callback, oknodes, konodes)
|
||||
return AclNode(callback, oknodes, konodes)
|
||||
|
||||
|
||||
@register.tag('can_create')
|
||||
|
@ -287,7 +312,7 @@ def acl_model_filter(parser, token):
|
|||
# {% can_create_end %}
|
||||
assert token.contents == 'acl_end'
|
||||
|
||||
return AclModelNode(callback, oknodes, konodes, *args)
|
||||
return AclNode(callback, oknodes, konodes, *args)
|
||||
|
||||
|
||||
@register.tag('can_edit')
|
||||
|
@ -327,23 +352,9 @@ def acl_instance_filter(parser, token):
|
|||
return AclInstanceNode(tag_name, instance_name, oknodes, konodes, *args)
|
||||
|
||||
|
||||
class AclAppNode(Node):
|
||||
"""A node for compiled ACL block when ACL is based on application."""
|
||||
|
||||
def __init__(self, callback, oknodes, konodes):
|
||||
self.callback = callback
|
||||
self.oknodes = oknodes
|
||||
self.konodes = konodes
|
||||
|
||||
def render(self, context):
|
||||
can, _ = self.callback(context['user'])
|
||||
if can:
|
||||
return self.oknodes.render(context)
|
||||
return self.konodes.render(context)
|
||||
|
||||
|
||||
class AclModelNode(Node):
|
||||
"""A node for the compiled ACL block when acl is base on model"""
|
||||
class AclNode(Node):
|
||||
"""A node for the compiled ACL block when acl callback doesn't require
|
||||
context."""
|
||||
|
||||
def __init__(self, callback, oknodes, konodes, *args):
|
||||
self.callback = callback
|
||||
|
|
Loading…
Reference in a new issue