0

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

问题是,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_custom_principals它是resolve_principals的副本,但使用我自己的 ACE 进行了扩展,例如(Allow, "mygroup:admin", "add")...

阅读日志,上面一行的上下文具有正确的acl ,包括自定义 ACE。为什么 Pyramid 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', 'user:74', 'mygroup:admin', 'mygroup:manager', 'team_member:1']
<websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> & add
******CONTEXT & PERMISSION
[('Allow', 'mygroup:admin', 'add'), ('Allow', 'mygroup:manager', 'add'), ('Allow', 'mygroup:senior', 'add'), ('Allow', 'mygroup:assistant', 'add'), ('Deny', 'mygroup:legcle', 'add'), ('Deny', 'mygroup:clerk', 'add'), ('Deny', 'mygroup:intern', 'add'), ('Allow', 'mygroup:admin', 'edit'), ('Allow', 'mygroup:manager', 'edit')]
******+++++++CONTEXT ACL
ACLDenied permission 'add' via ACE '<default deny>' in ACL [('Allow', 'system.Authenticated', 'authenticated'), ('Allow', 'superuser:superuser', 'shell'), ('Allow', 'system.Everyone', 'view')] on context <websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> for principals ['system.Everyone', 'system.Authenticated', 74, 'system.Authenticated', 'user:74']
-------------HAS PERMISSION EVAL
<websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> & add
******CONTEXT & PERMISSION
[('Allow', 'mygroup:admin', 'add'), ('Allow', 'mygroup:manager', 'add'), ('Allow', 'mygroup:senior', 'add'), ('Allow', 'mygroup:assistant', 'add'), ('Deny', 'mygroup:legcle', 'add'), ('Deny', 'mygroup:clerk', 'add'), ('Deny', 'mygroup:intern', 'add'), ('Allow', 'mygroup:admin', 'edit'), ('Allow', 'mygroup:manager', 'edit')]
******+++++++CONTEXT ACL
ACLDenied permission 'add' via ACE '<default deny>' in ACL [('Allow', 'system.Authenticated', 'authenticated'), ('Allow', 'superuser:superuser', 'shell'), ('Allow', 'system.Everyone', 'view')] on context <websauna.myaddon.crud.org.OrgResource object at 0x7fa021f883c8> for principals ['system.Everyone', 'system.Authenticated', 74, 'system.Authenticated', '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:
我正在使用:
Pyramid 1.10.4
Websauna 1.0a13

4

1 回答 1

0

我怀疑 websauna 没有调用您的resolve_custom_principals功能,而是使用其默认resolve_principals功能?我认为很明显,在has_permission调用时引入的主体不是来自您的resolve_custom_principals函数的主体,因此某些东西没有与此覆盖正确连接。

于 2020-12-10T19:50:22.510 回答