fixed:issue#34

This commit is contained in:
JaguarJack 2021-09-14 14:45:51 +08:00
parent 3728bd2068
commit f7299bb247

View File

@ -6,6 +6,10 @@ use catchAdmin\permissions\model\Permissions;
use catcher\CatchCacheKeys; use catcher\CatchCacheKeys;
use catcher\Code; use catcher\Code;
use catcher\exceptions\PermissionForbiddenException; use catcher\exceptions\PermissionForbiddenException;
use Closure;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\facade\Cache; use think\facade\Cache;
use catcher\Utils; use catcher\Utils;
@ -15,14 +19,14 @@ class PermissionsMiddleware
* *
* @time 2019年12月12日 * @time 2019年12月12日
* @param Request $request * @param Request $request
* @param \Closure $next * @param Closure $next
* @return mixed * @return mixed
* @throws \think\db\exception\DataNotFoundException * @throws DataNotFoundException
* @throws \think\db\exception\DbException * @throws DbException
* @throws \think\db\exception\ModelNotFoundException * @throws ModelNotFoundException
* @throws PermissionForbiddenException * @throws PermissionForbiddenException|\ReflectionException
*/ */
public function handle(Request $request, \Closure $next) public function handle(Request $request, Closure $next)
{ {
$rule = $request->rule()->getName(); $rule = $request->rule()->getName();
@ -54,7 +58,8 @@ class PermissionsMiddleware
$permission = property_exists($request, 'permission') ? $request->permission : $permission = property_exists($request, 'permission') ? $request->permission :
$this->getPermission($module, $controller, $action); $this->getPermission($module, $controller, $action);
if (!$permission || !in_array($permission->id, Cache::get(CatchCacheKeys::USER_PERMISSIONS . $user->id))) { $permissionIds = Cache::get(CatchCacheKeys::USER_PERMISSIONS . $user->id);
if (!$permission || ! in_array($permission->id, (array)$permissionIds)) {
throw new PermissionForbiddenException(); throw new PermissionForbiddenException();
} }
@ -67,11 +72,10 @@ class PermissionsMiddleware
* @param $module * @param $module
* @param $controllerName * @param $controllerName
* @param $action * @param $action
* @param $request * @return array|\think\Model|null
* @throws \think\db\exception\DataNotFoundException * @throws DbException
* @throws \think\db\exception\DbException * @throws ModelNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws DataNotFoundException
* @return array|bool|\think\Model|null
*/ */
protected function getPermission($module, $controllerName, $action) protected function getPermission($module, $controllerName, $action)
{ {