【发布时间】:2016-09-13 10:40:31
【问题描述】:
是否有任何库/解决方案提供对资源的部分访问?这样的权限控制怎么叫?
大多数 ACL 库完全允许/拒绝操作:
user.create
user.update
user.show
但是如果应该有“部分”权限怎么办。 比如:
- 您只能查看 活跃 角色为 guest 或 moderator 的用户。
- 您可以编辑具有设计师角色的用户,但只能编辑他的电话和邮件。
第一个示例可能如下所示:
权限:
user.show
特权:
status => active
&&
role => guest || moderator
第二个:
权限:
user.edit
特权:
editable => phone, mail
更新:
为了让我的问题更清楚,我添加了这个用法示例,以展示(在我的想法中)它的样子。
// global access
if($user->can('user.show')){
// get the privileges provided by the permissions
$filter = $user->getPrivilegesFor('user.show');
// use the privileges to filter the (database)query
// (using the example above the filter should restrict to active guests and moderators)
$result = $repo->getUsers($filter);
}else{
// access denied
}
// use the result to fill the view
【问题讨论】:
标签: php permissions acl