为 Zend 导航页面授予多个 ACL 权限

发布于 2024-08-25 09:09:19 字数 1266 浏览 7 评论 0原文

我正在使用 Zend_Navigation 并尝试将其与 Zend_Acl 集成。导航中的每个页面都有一个privilege 属性。我无法确定的是如何为单个页面定义多个权限。

用例:用于管理用户的页面。如果当前登录用户的角色具有 addeditdelete 权限,我想在导航中显示该页面>用户资源。

导航 XML 中的示例条目:

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>add,edit,delete</privilege>
</admin_users>

使用上面的逗号分隔列表并不能提供所需的行为。


更新

深入研究代码后,我发现 Zend_Navigation_Page 只允许单个字符串值。有没有人扩展了这个类或找到了解决此限制的另一种方法?

/**
 * Sets ACL privilege associated with this page
 *
 * @param  string|null $privilege  [optional] ACL privilege to associate
 *                                 with this page. Default is null, which
 *                                 sets no privilege.
 * @return Zend_Navigation_Page    fluent interface, returns self
 */
public function setPrivilege($privilege = null)
{
    $this->_privilege = is_string($privilege) ? $privilege : null;
    return $this;
}

I'm using Zend_Navigation and am trying to integrate it with Zend_Acl. Each page in the navigation has a privilege attribute. What I can't determine is how to define multiple privileges for a single page.

Use case: A page that is for managing users. I want to display that page (in navigation) if the current signed in user's role has add, edit, or delete privileges on the Users resource.

Example entry in the navigation XML:

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>add,edit,delete</privilege>
</admin_users>

Using a comma-separated list as above doesn't lend the desired behavior.


UPDATE

After digging through the code, I found that Zend_Navigation_Page only allows a single string value. Has anyone extended this class or found another way around this limitation?

/**
 * Sets ACL privilege associated with this page
 *
 * @param  string|null $privilege  [optional] ACL privilege to associate
 *                                 with this page. Default is null, which
 *                                 sets no privilege.
 * @return Zend_Navigation_Page    fluent interface, returns self
 */
public function setPrivilege($privilege = null)
{
    $this->_privilege = is_string($privilege) ? $privilege : null;
    return $this;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾其所爱 2024-09-01 09:09:19

我意识到我的问题是我缺乏“查看”类型的权限。当我加载资源权限时,如果用户对该资源具有任何权限,我现在会授予该资源的“管理员”权限。然后我在页面上使用“管理员”权限。

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>admin</privilege>
</admin_users>

I realized that my problem was my lack of a 'view' type permission. When I'm loading the resource privileges, I now grant an 'admin' privilege on the resource if the user has any privileges for that resource. I then use the 'admin' privilege on the page.

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>admin</privilege>
</admin_users>
征﹌骨岁月お 2024-09-01 09:09:19

可能需要某种嵌套才能将权限作为数组传递:

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>
        <add>add</add>
        <edit>edit</edit>
    </privilege>
</admin_users>

编辑:

常识告诉我们一个链接应该指向一个操作。您可以将 节点添加到菜单中。

<admin_users_edit>
    <label>Users edit</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <params>
       <do>edit</do>
    </params>
    <privilege>
        <edit>edit</edit>
    </privilege>
</admin_users_edit>


<admin_users_delete>
    <label>Users delete</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <params>
       <do>delete</do>
    </params>
    <privilege>
        <edit>delete</edit>
    </privilege>
</admin_users_delete>

Probably some kind of nesting is required to pass the privileges as an array:

<admin_users>
    <label>Users</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <privilege>
        <add>add</add>
        <edit>edit</edit>
    </privilege>
</admin_users>

Edit:

Common sense tells that one link should point to one action. You may add <params> nodes to the menu.

<admin_users_edit>
    <label>Users edit</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <params>
       <do>edit</do>
    </params>
    <privilege>
        <edit>edit</edit>
    </privilege>
</admin_users_edit>


<admin_users_delete>
    <label>Users delete</label>
    <route>default</route>
    <controller>admin</controller>
    <action>users</action>
    <resource>Users</resource>
    <params>
       <do>delete</do>
    </params>
    <privilege>
        <edit>delete</edit>
    </privilege>
</admin_users_delete>
却一份温柔 2024-09-01 09:09:19

您尝试过以下方法吗?我不确定它是否会起作用,但我有一种感觉。

<admin_users>
<label>Users</label>
<route>default</route>
<controller>admin</controller>
<action>users</action>
<resource>Users</resource>
<privilege>add</privilege>
<privilege>edit</privilege>
<privilege>delete</privilege>

Have you tried the following? I'm not sure if it would work, but I have a feeling it would.

<admin_users>
<label>Users</label>
<route>default</route>
<controller>admin</controller>
<action>users</action>
<resource>Users</resource>
<privilege>add</privilege>
<privilege>edit</privilege>
<privilege>delete</privilege>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文