修改权限管理
This commit is contained in:
parent
17d30f1cc3
commit
b5e90dd14f
@ -2,19 +2,26 @@
|
|||||||
|
|
||||||
namespace catchAdmin\permissions;
|
namespace catchAdmin\permissions;
|
||||||
|
|
||||||
|
use catchAdmin\permissions\model\Permissions;
|
||||||
|
use catcher\CatchAdmin;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
class OperateLogListener
|
class OperateLogListener
|
||||||
{
|
{
|
||||||
public function handle($params)
|
public function handle($params)
|
||||||
{
|
{
|
||||||
|
$request = $params['request'];
|
||||||
|
$permission = $params['permission'];
|
||||||
|
|
||||||
Db::name('operate_log')->insert([
|
Db::name('operate_log')->insert([
|
||||||
'module' => $params['module'],
|
'creator_id' => $request->user()->id,
|
||||||
'ip' => request()->ip(),
|
'module' => Permissions::where('id', $permission->parent_id)->value('permission_name'),
|
||||||
'operate' => $params['operate'],
|
'method' => $request->method(),
|
||||||
'creator_id' => $params['uid'],
|
'operate' => $permission->permission_name,
|
||||||
'method' => $params['method'],
|
'route' => $permission->route,
|
||||||
|
'params' => json_encode($request->param()),
|
||||||
'created_at' => time(),
|
'created_at' => time(),
|
||||||
|
'ip' => $request->ip(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ class PermissionsMiddleware
|
|||||||
}
|
}
|
||||||
// toad
|
// toad
|
||||||
if (($permission = $this->getPermission($request))
|
if (($permission = $this->getPermission($request))
|
||||||
&& in_array($permission->id, $request->user()->getPermissionsBy())) {
|
&& !in_array($permission->id, $request->user()->getPermissionsBy())) {
|
||||||
throw new PermissionForbiddenException();
|
throw new PermissionForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,21 +57,18 @@ class PermissionsMiddleware
|
|||||||
|
|
||||||
$module = array_pop($controller);
|
$module = array_pop($controller);
|
||||||
|
|
||||||
$permissionMark = sprintf('%s:%s:%s', $module, $controllerName, $action);
|
$permissionMark = sprintf('%s:%s', $controllerName, $action);
|
||||||
|
$permission = Permissions::where('module', $module)->where('permission_mark', $permissionMark)->find();
|
||||||
$permission = Permissions::where('permission_mark', $permissionMark)->find();
|
|
||||||
|
|
||||||
|
|
||||||
$params['uid'] = $request->user()->id;
|
|
||||||
$params['module'] = $rule ? CatchAdmin::getModulesInfo(false)[$module] : '首页';
|
|
||||||
$params['method'] = $request->method();
|
|
||||||
$params['operate'] = sprintf('%s/%s', $controllerName, $action);
|
|
||||||
event('operateLog', $params);
|
|
||||||
|
|
||||||
if (!$permission) {
|
if (!$permission) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event('operateLog', [
|
||||||
|
'request' => $request,
|
||||||
|
'permission' => $permission,
|
||||||
|
]);
|
||||||
|
|
||||||
return $permission;
|
return $permission;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -34,7 +34,7 @@ class Roles extends Migrator
|
|||||||
->addColumn('description', 'string',['default'=> '','comment'=>'角色备注'])
|
->addColumn('description', 'string',['default'=> '','comment'=>'角色备注'])
|
||||||
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
||||||
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
||||||
->addColumn('deleted_at', 'integer', array('null'=>true,'comment'=>'删除状态,0未删除 >0 已删除', 'signed' => false))
|
->addColumn('deleted_at', 'integer', array('default'=>0,'comment'=>'删除状态,0未删除 >0 已删除', 'signed' => false))
|
||||||
->create();
|
->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class Permissions extends Migrator
|
|||||||
->addColumn('sort', 'integer',['default'=> 0,'comment'=>'排序字段'])
|
->addColumn('sort', 'integer',['default'=> 0,'comment'=>'排序字段'])
|
||||||
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
->addColumn('created_at', 'integer', array('default'=>0,'comment'=>'创建时间', 'signed' => false ))
|
||||||
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
->addColumn('updated_at', 'integer', array('default'=>0,'comment'=>'更新时间', 'signed' => false))
|
||||||
->addColumn('deleted_at', 'integer', array('null'=>true,'comment'=>'删除状态,null 未删除 timestamp 已删除', 'signed' => false))
|
->addColumn('deleted_at', 'integer', array('default'=>0,'comment'=>'删除状态,null 未删除 timestamp 已删除', 'signed' => false))
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user