10000 dcat 的权限使用问题 · Issue #1729 · jqhph/dcat-admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

dcat 的权限使用问题 #1729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yuchen opened this issue Apr 16, 2022 · 2 comments
Open

dcat 的权限使用问题 #1729

yuchen opened this issue Apr 16, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@yuchen
Copy link
yuchen commented Apr 16, 2022
  • Laravel Version: 8.61.0
  • PHP Version: 8.0.18
  • Dcat Admin Version: 2.1.5-beta

Description:

背景:前期项目使用 laravel 做服务端,提供 api(粗算了下 route 有 500+),中间一段时间前端开发资源紧张,引入了 DcatAdmin,后端直接写页面。

文档中提及,共有 3 种方式启用权限:

  1. 通过路由控制(但是由于 dcat 是后期接入,路由会被拼接admin.route.prefix⚠️ 截止220413我没找到合适的方法
  2. 通过中间件的形式控制(目前启用的是这种 ✅
Route::prefix('xxx_task')->namespace('Goods')->middleware([
    'xxx.refresh',
    'admin.permission:allow,administrator,spu-mgr', //`角色`名 role
])->group(function () {
    Route::get('list', 'XxxTaskController@list');
    //其他省略
});
  1. 使用提供的相关方法,提供更细粒度的控制
Admin::user()->isRole('developer');  //用户是否有某个角色
Admin::user()->can('create-post'); //是否有某个权限
Admin::user()->cannot('delete-post');  //是否没有某个权限
Admin::user()->isAdministrator();  //是否是超级管理员
Admin::user()->inRoles(['editor', 'developer']); //是否是其中的角色

但是我在使用2方案的时候,遇到了如下问题

Steps To Reproduce:

配置 'admin.permission:allow,administrator,spu-mgr' 在调用中间件的时候,执行如下代码

// Dcat\Admin\Http\Middleware/Permission
public function handle(Request $request, \Closure $next, ...$args)
{
    $user = Admin::user();

    if (
        ! $user
        || ! empty($args) // ⚠️ 这里条件判定为 true
        || ! config('admin.permission.enable')
        || $this->shouldPassThrough($request)
        || $user->isAdministrator()
        || $this->checkRoutePermission($request)
    ) {
        // ⚠️ 会走到这里,直接跳过了权限检查…
        return $next($request);
    }

    if (! $user->allPermissions()->first(function ($permission) use ($request) {
        return $permission->shouldPassThrough($request);
    })) {
        Checker::error();
    }

    return $next($request);
}

🙏 不知是不是我哪里理解错了…

@jqhph jqhph added the bug Something isn't working label Apr 17, 2022
@jqhph
Copy link
Owner
jqhph commented Apr 17, 2022

方案2确实有问题

@yuchen
Copy link
Author
yuchen commented Apr 24, 2022

然后我只能想办法绕回用 方案 1,但是代码我理解错了,用了 controller.action 这种形式… 还是不行。😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants
0