windhoney / yii2-rest-rbac Goto Github PK
View Code? Open in Web Editor NEWyii2 rbac yii2 rest RBAC Auth manager for Yii2 RESTful(YII2权限管理rbac--rest接口方式)
Home Page: https://windhoney.gitbooks.io/yii2-rest-rbac/
License: MIT License
yii2 rbac yii2 rest RBAC Auth manager for Yii2 RESTful(YII2权限管理rbac--rest接口方式)
Home Page: https://windhoney.gitbooks.io/yii2-rest-rbac/
License: MIT License
??
应该是PHP7新增的吧。
我测试环境是PHP5.6,可以通过composer安装这个模块,但因为有类似开头说的PHP7的特性,所以运行时就报错了:
syntax error, unexpected '?'
所以,希望可以增加requirements之类的说明,或者在composer.json里做限制。
yii2-rest-rbac/models/Menu.php
Line 199 in 4cbd9ee
这个是不是可以通过authManager
来获取?
Yii::$app->getAuthManager()->itemTable
@windhoney 能给我一个完整的demo吗?
components/DbManager.php 157
$this->db->createCommand()
->insert($this->itemTable, [
'name' => $item->name,
'type' => $item->type,
'description' => $item->description,
'parent_name' => $item->parent_name ?? '',
'rule_name' => $item->ruleName,
'data' => $item->data === null ? null : serialize($item->data),
'created_at' => $item->createdAt,
'updated_at' => $item->updatedAt,
])->execute
上述的代码中有
'parent_name' => $item->parent_name ?? '',
上面的代码出错了?
models/serachs/User.php里的filedlist多了一个字段role
php yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/migrations
需要换成
php yii migrate --migrationPath=@vendor/filsh/yii2-oauth2-server/src/migrations
首先感谢@windhoney还在更新。现在遇到这样一个问题,想请教一下解决方案。我们前端是vuejs+element-ui,接口就是yii2了。基于现在的rbac解决方案,可以控制某个路由级的权限,比如说create、update、delete等。现在有一个情况是,在一个订单展示页面,不同角色的用户可以查询的内容不一样,比如说admin可以查询订单的价格、数量、利润,而普通员工则只能查询价格和数量。价格、数量、利润这三个查询项是以三个button来展示的,我想的是,如果是admin则在页面上展示这三个button,如果是普通员工则只展示前两个button。因为是前后端分离的,那么在展示这个页面的时候是不是就应该知道该展示哪些button?这个数据是不是应该由接口返回呢,如果说是接口返回的话,那么接口怎么根据不同的角色来确定显示哪些元素并将数据返回去前段。@windhoney你有遇到这样的权限处理场景吗?
class Configs extends \yii\base\Object 调整为 extends \yii\base\BaseObject
调整public $menuTable = '{{%menu}}';public $userTable = '{{%user}}';
基于当前的实现,根据parent_name可以将路由分组,但是只是二级目录显示,一般我们给前端的是树形多级分组
|----客户
| |----客户管理
| | |----添加客户
| | |----删除客户
|----订单
| |----订单管理
其实真正的叶子节点才是权限,目前我采取的方案是,新增auth_group表,这个表存的树形的分组,
|id | name | parent|
将auth_item表中的parent_name改成goup_id,即关联auth_group表中的id。
想让某个权限节点在哪一层分组就赋予对应的group_id,这样的话,我们只关心两点,一是权限分组结构,二是某个权限放在哪个分组。这样分开处理后,更加清晰和容易管理,而且可以实现树形多级分组。
RouteController中
public function getRoutes()
{
$manager = Yii::$app->getAuthManager();
$routes = $this->getAppRoutes();
// print_r($routes);die;
$exists = [];
foreach ($manager->getPermissions() as $name) {
$name = ArrayHelper::toArray($name);
if ($name['name'][0] !== '/') {
continue;
}
$route['name'] = $name['name'];
$route['description'] = $name['description'];
$route['parent_name'] = $name['parent_name'];
$exists[] = $route;
unset($routes[$name['name']]);
}
$exists = ArrayHelper::index($exists, null, 'parent_name');
return [
'avaliable' => array_keys($routes),
'assigned' => $exists
];
}
取了‘parent_name’字段,但是数据库表中没有这个字段啊
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.