Commit fc4fb56c authored by 孙磊's avatar 孙磊

角色权限信息调整

Signed-off-by: 孙磊's avatarsunlei <sunlei@romens.cn>
parent 8550b4bf
......@@ -346,10 +346,29 @@ class AuthorityNodeController extends BaseController
*/
public function actionRoleAuthorities()
{
//获取登陆用户的权限信息
$rbac = new ShopRbacUser();
$nodeModel = new ShopRbacNode();
$model = new ShopRbacRole();
$roleAcessModel = new ShopRbacRoleAccess();
$nodeModel = new ShopRbacNode();
//用户输入数据赋值到模型属性
//获取登陆用户节点信息
$userGuid = Yii::$app->user->identity->GUID;
$userinfo = $rbac->getRbacUserInfo($userGuid);
$cur_role_id = $userinfo['ROLE_ID'];
$cur_auth_all = $roleAcessModel->getRoleAuthorities($cur_role_id);
//获取登陆用户节点ID
$cur_role_nodes = array();
foreach ($cur_auth_all as $k => $v) {
$cur_role_nodes[] = $v['NODE_ID'];
}
if ($cur_role_nodes) {
$cur_role_authorities = $nodeModel->getRoleAuthrities($cur_role_nodes);
//调整节点关系
$cur_role_authorities = $this->getTree($cur_role_authorities);
} else {
$cur_role_authorities = '';
}
//每个角色拥有的节点信息获取
$params = Yii::$app->request->queryParams;
$id = $model->ID = $params['ID'];
$name = $model->NAME = $params['NAME'];
......@@ -357,24 +376,26 @@ class AuthorityNodeController extends BaseController
//获取角色的权限
$info = $roleAcessModel->getRoleAuthorities($id);
if (!$info) {
throw new BadRequestHttpException('没有找到角色的权限信息');
// throw new BadRequestHttpException('没有找到角色的权限信息');
return $roleHasAuthInfo = '';
}
//获取节点ID
$role_nodes = array();
$roleHasAuthID = array();
foreach ($info as $k => $v) {
$role_nodes[] = $v['NODE_ID'];
}
//获取角色拥有的权限节点信息
if ($role_nodes) {
$role_authorities = $nodeModel->getRoleAuthrities($role_nodes);
//调整节点关系
$role_authorities = $this->getTree($role_authorities);
$roleHasAuthID[] = $v['NODE_ID'];
}
if (!$role_authorities) {
throw new BadRequestHttpException('没有找到角色的权限节点信息');
if ($roleHasAuthID) {
$roleHasAuthInfo = implode(',', $roleHasAuthID);
} else {
$roleHasAuthInfo = '';
}
$role_authorities[0]['ROLE_NAME'] = $name;
return $role_authorities;
//拼装数组
$roleNodeInfo = array(
'cur_role_nodes' => $cur_role_authorities,
'every_role_node_ids' => $roleHasAuthInfo,
'every_role_name' => $name
);
return $roleNodeInfo;
} else {
//验证失败:$errors 是一个包含错误信息的数组
Yii::$app->response->statusCode = 422;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment