|
@@ -256,7 +256,7 @@ class Group extends Apic
|
|
|
$this->error();
|
|
|
}
|
|
|
|
|
|
- public function simple_list(){
|
|
|
+/* public function simple_list(){
|
|
|
$ruleList = collection(model('AuthRule')->field('id,title as name,pid as parentId,type')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray();
|
|
|
|
|
|
$this->success(1,$ruleList);
|
|
@@ -274,14 +274,15 @@ class Group extends Apic
|
|
|
unset($val);
|
|
|
|
|
|
$this->success(1,$rules);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* 读取角色权限树
|
|
|
*
|
|
|
* @internal
|
|
|
*/
|
|
|
- public function roletree()
|
|
|
+ //来自admin/auth/group/roletree
|
|
|
+ public function simple_list()
|
|
|
{
|
|
|
$this->loadlang('auth/group');
|
|
|
|
|
@@ -335,6 +336,7 @@ class Group extends Apic
|
|
|
return $item['id'];
|
|
|
}, $parentRuleList);
|
|
|
$nodeList = [];
|
|
|
+ $result = [];
|
|
|
foreach ($parentRuleList as $k => $v) {
|
|
|
if (!$superadmin && !in_array($v['id'], $adminRuleIds)) {
|
|
|
continue;
|
|
@@ -344,8 +346,88 @@ class Group extends Apic
|
|
|
}
|
|
|
$state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens));
|
|
|
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
|
|
|
+ $result[] = array('id' => $v['id'], 'parentId' => $v['pid'] ? $v['pid'] : 0, 'name' => $v['title'], 'type' => $v['type']);
|
|
|
+ }
|
|
|
+ $this->success(1, $result);
|
|
|
+ } else {
|
|
|
+ $this->error(__('Can not change the parent to child'));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $this->error(__('Group not found'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //来自admin/auth/group/roletree
|
|
|
+ public function list_role_menus()
|
|
|
+ {
|
|
|
+ $this->loadlang('auth/group');
|
|
|
+
|
|
|
+ $model = model('AuthGroup');
|
|
|
+ $id = $this->request->post("id");
|
|
|
+ $pid = $this->request->post("pid");
|
|
|
+ $parentGroupModel = $model->get($pid);
|
|
|
+ $currentGroupModel = null;
|
|
|
+ if ($id) {
|
|
|
+ $currentGroupModel = $model->get($id);
|
|
|
+ }
|
|
|
+ if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) {
|
|
|
+ $id = $id ? $id : null;
|
|
|
+ $ruleList = collection(model('AuthRule')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray();
|
|
|
+ //读取父类角色所有节点列表
|
|
|
+ $parentRuleList = [];
|
|
|
+ if (in_array('*', explode(',', $parentGroupModel->rules))) {
|
|
|
+ $parentRuleList = $ruleList;
|
|
|
+ } else {
|
|
|
+ $parentRuleIds = explode(',', $parentGroupModel->rules);
|
|
|
+ foreach ($ruleList as $k => $v) {
|
|
|
+ if (in_array($v['id'], $parentRuleIds)) {
|
|
|
+ $parentRuleList[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $ruleTree = new Tree();
|
|
|
+ $groupTree = new Tree();
|
|
|
+ //当前所有正常规则列表
|
|
|
+ $ruleTree->init($parentRuleList);
|
|
|
+ //角色组列表
|
|
|
+ $groupTree->init(collection(model('AuthGroup')->where('id', 'in', $this->childrenGroupIds)->select())->toArray());
|
|
|
+
|
|
|
+ //读取当前角色下规则ID集合
|
|
|
+ $adminRuleIds = $this->auth->getRuleIds();
|
|
|
+ //是否是超级管理员
|
|
|
+ $superadmin = $this->auth->isSuperAdmin();
|
|
|
+ //当前拥有的规则ID集合
|
|
|
+ $currentRuleIds = $id ? explode(',', $currentGroupModel->rules) : [];
|
|
|
+
|
|
|
+ if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) {
|
|
|
+ $parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name');
|
|
|
+ $hasChildrens = [];
|
|
|
+ foreach ($parentRuleList as $k => $v) {
|
|
|
+ if ($v['haschild']) {
|
|
|
+ $hasChildrens[] = $v['id'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $parentRuleIds = array_map(function ($item) {
|
|
|
+ return $item['id'];
|
|
|
+ }, $parentRuleList);
|
|
|
+ $nodeList = [];
|
|
|
+ $selected = [];//需要返回的东西
|
|
|
+ foreach ($parentRuleList as $k => $v) {
|
|
|
+ if (!$superadmin && !in_array($v['id'], $adminRuleIds)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ($v['pid'] && !in_array($v['pid'], $parentRuleIds)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens));
|
|
|
+ $nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
|
|
|
+ //需要返回的东西
|
|
|
+ if(in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens)){
|
|
|
+ $selected[] = $v['id'];
|
|
|
+ }
|
|
|
}
|
|
|
- $this->success('', null, $nodeList);
|
|
|
+ $this->success(1, $selected);
|
|
|
} else {
|
|
|
$this->error(__('Can not change the parent to child'));
|
|
|
}
|