优化菜单规则支持子路径检测

pull/516/MERGE
Karson 2025-12-18 11:44:41 +08:00
parent 2a5f3e97db
commit fdf92e550e
1 changed files with 7 additions and 3 deletions

View File

@ -152,14 +152,18 @@ class Backend extends Controller
$url = $url ? $url : $this->request->url(); $url = $url ? $url : $this->request->url();
if (in_array($this->request->pathinfo(), ['/', 'index/index'])) { if (in_array($this->request->pathinfo(), ['/', 'index/index'])) {
$this->redirect('index/login', [], 302, ['referer' => $url]); $this->redirect('index/login', [], 302, ['referer' => $url]);
exit;
} }
$this->error(__('Please login first'), url('index/login', ['url' => $url])); $this->error(__('Please login first'), url('index/login', ['url' => $url]));
} }
// 判断是否需要验证权限 // 判断是否需要验证权限
if (!$this->auth->match($this->noNeedRight)) { if (!$this->auth->match($this->noNeedRight)) {
// 判断控制器和方法是否有对应权限 // 判断控制器和方法是否有对应权限
if (!$this->auth->check($path)) { $subpath = str_replace('.', '/', $this->request->path());
// 判断当前路径和子路径是否都无权限
$hasPathPermission = $this->auth->check($path);
$hasSubpathPermission = ($path === $subpath) ? $hasPathPermission : $this->auth->check($subpath);
if (!$hasPathPermission && !$hasSubpathPermission) {
Hook::listen('admin_nopermission', $this); Hook::listen('admin_nopermission', $this);
$this->error(__('You have no permission'), ''); $this->error(__('You have no permission'), '');
} }