1.菜单规则权限管理
2.备份数据库
This commit is contained in:
@@ -42,7 +42,8 @@ class Auth
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->getChildren($this->children[0]);
|
||||
$menus = $this->getChildren($this->children[0]);
|
||||
return $this->filterVisibleMenus($menus, $uid);
|
||||
}
|
||||
|
||||
private function getChildren(array $rules): array
|
||||
@@ -55,6 +56,55 @@ class Auth
|
||||
return $rules;
|
||||
}
|
||||
|
||||
private function filterVisibleMenus(array $menus, int $uid): array
|
||||
{
|
||||
$ruleList = $this->getRuleList($uid);
|
||||
if (in_array('*', $ruleList, true)) {
|
||||
return $menus;
|
||||
}
|
||||
|
||||
$allowedRuleMap = [];
|
||||
foreach ($ruleList as $ruleName) {
|
||||
if (is_string($ruleName) && $ruleName !== '') {
|
||||
$allowedRuleMap[strtolower($ruleName)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->doFilterVisibleMenus($menus, $allowedRuleMap);
|
||||
}
|
||||
|
||||
private function doFilterVisibleMenus(array $menus, array $allowedRuleMap): array
|
||||
{
|
||||
$visibleMenus = [];
|
||||
foreach ($menus as $menu) {
|
||||
if (!is_array($menu)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$children = $menu['children'] ?? [];
|
||||
if (is_array($children) && $children) {
|
||||
$menu['children'] = $this->doFilterVisibleMenus($children, $allowedRuleMap);
|
||||
}
|
||||
|
||||
$name = strtolower(strval($menu['name'] ?? ''));
|
||||
$type = strval($menu['type'] ?? '');
|
||||
$isAllowed = $name !== '' && isset($allowedRuleMap[$name]);
|
||||
|
||||
if ($type === 'button') {
|
||||
if ($isAllowed) {
|
||||
$visibleMenus[] = $menu;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isAllowed || !empty($menu['children'])) {
|
||||
$visibleMenus[] = $menu;
|
||||
}
|
||||
}
|
||||
|
||||
return $visibleMenus;
|
||||
}
|
||||
|
||||
public function check(string $name, int $uid, string $relation = 'or', string $mode = 'url'): bool
|
||||
{
|
||||
$ruleList = $this->getRuleList($uid);
|
||||
|
||||
Reference in New Issue
Block a user