金字塔/ Websauna的ACL权限不一致

问题描述

我正在对Websauna上的is_visible方法进行故障排除,因为该方法无法正常工作(至少对我而言)。可以找到文件here

问题是,似乎ACL上下文从上面显示的一行突然改变了。这是带有打印日志的方法

def is_visible(self,context: Resource,request: Request) -> bool:
    """Determine if we should render this button.

    :param context: Traversal context
    :param request: Current HTTP Request.
    :returns: Boolean indicating if button is visible or not.
    """
    visible = True
    if self.permission is not None:
        print(context,'&',self.permission)
        print('******CONTEXT & PERMISSION')
        print(context.__acl__)
        print('******+++++++CONTEXT ACL')
        print(request.has_permission(self.permission,context))
        print('-------------HAS PERMISSION EVAL')
        if not request.has_permission(self.permission,context):
            visible = False

    if self.feature is not None:
        if self.feature not in request.registry.features:
            visible = False

    return visible

以下是日志,显示context与拒绝访问时has_permission()所引用的值如何不同。


下面的日志中的前两行显示了对resolve_principals的副本resolve_custom_principals调用,但扩展了我自己的ACE,例如(Allow,"mygroup:admin","add") ...

在读取日志时,上面一行的上下文具有正确的 acl 包括自定义ACE。在下一行检查权限时,为什么金字塔ACL使用不同的上下文?在这种情况下返回ACLDenied。

[11:13:01] [websauna.myaddon.auth.principals resolve_custom_principals] ['system.Authenticated','user:74','mygroup:admin','mygroup:manager','team_member:1']
[11:13:01] [websauna.myaddon.auth.principals resolve_custom_principals] ['system.Authenticated','team_member:1']
<websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> & add
******CONTEXT & PERMISSION
[('Allow','add'),('Allow','mygroup:senior','mygroup:assistant',('Deny','mygroup:legcle','mygroup:clerk','mygroup:intern','edit'),'edit')]
******+++++++CONTEXT ACL
ACLDenied permission 'add' via ACE '<default deny>' in ACL [('Allow','system.Authenticated','authenticated'),'superuser:superuser','shell'),'system.Everyone','view')] on context <websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> for principals ['system.Everyone',74,'user:74']
-------------HAS PERMISSION EVAL
<websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> & add
******CONTEXT & PERMISSION
[('Allow','user:74']
-------------HAS PERMISSION EVAL
[11:13:01] [websauna.system.core.session create_session] Skipped session creation for http://localhost:6543/websauna-static/bootstrap.min.css

请让我知道是否需要更多信息,或者我如何使问题更清楚。

更新1: 在视图模板中调用is_visible函数以确定要呈现的按钮。就我而言,它没有显示按钮,但是在上下文中设置了权限。

<div id="crud-page-buttons" class="header-resources">
    {% for button in resource_buttons %}
        {% if button.is_visible(context,request) %}
            {{ button.render(context,request)|safe }}
        {% endif %}
    {% endfor %}
</div>

更新2:
我正在使用:
金字塔1.10.4
Websauna 1.0a13

解决方法

我怀疑websauna不会调用您的resolve_custom_principals函数,而是使用其默认的resolve_principals函数吗?我认为很明显,调用has_permission时引入的委托人不是您的resolve_custom_principals函数中的委托人,因此使用此替代无法正确连接某些东西。