增加操作事件
This commit is contained in:
parent
02b973d0b5
commit
5976ebb235
@ -1,7 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace catchAdmin\permissions;
|
||||
|
||||
class OperateEvent
|
||||
{
|
||||
use think\facade\Db;
|
||||
|
||||
class OperateLogListener
|
||||
{
|
||||
public function handle($params)
|
||||
{
|
||||
Db::name('operate_log')->insert([
|
||||
'module' => $params['module'],
|
||||
'ip' => request()->ip(),
|
||||
'operate' => $params['operate'],
|
||||
'creator_id' => $params['uid'],
|
||||
'method' => $params['method'],
|
||||
'created_at' => time(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ namespace catchAdmin\permissions;
|
||||
|
||||
use app\Request;
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\exceptions\PermissionForbiddenException;
|
||||
use think\helper\Str;
|
||||
|
||||
@ -25,7 +26,8 @@ class PermissionsMiddleware
|
||||
throw new PermissionForbiddenException('Login is invalid', 10006);
|
||||
}
|
||||
// toad
|
||||
if (($permission = $this->getPermission($request->rule()->getName())) && in_array($permission->id, $request->user()->getPermissionsBy())) {
|
||||
if (($permission = $this->getPermission($request))
|
||||
&& in_array($permission->id, $request->user()->getPermissionsBy())) {
|
||||
throw new PermissionForbiddenException();
|
||||
}
|
||||
|
||||
@ -35,17 +37,15 @@ class PermissionsMiddleware
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @param $rule
|
||||
* @param $request
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array|bool|\think\Model|null
|
||||
*/
|
||||
protected function getPermission($rule)
|
||||
protected function getPermission(Request $request)
|
||||
{
|
||||
if (!$rule) {
|
||||
return false;
|
||||
}
|
||||
$rule = $request->rule()->getName();
|
||||
|
||||
[$controller, $action] = explode(Str::contains($rule, '@') ? '@' : '/', $rule);
|
||||
|
||||
@ -57,18 +57,21 @@ class PermissionsMiddleware
|
||||
|
||||
$module = array_pop($controller);
|
||||
|
||||
$ignore = config('catch.ignore');
|
||||
|
||||
if (in_array($module, $ignore['module'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$permissionMark = sprintf('%s:%s:%s', $module, $controllerName, $action);
|
||||
|
||||
if (in_array($permissionMark, $ignore['route'])) {
|
||||
$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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Permissions::where('permission_mark', $permissionMark)->find();
|
||||
return $permission;
|
||||
}
|
||||
}
|
@ -56,14 +56,14 @@ class Permission extends CatchController
|
||||
$form->hidden('parent_id')->default(\request()->param('id') ?? 0);
|
||||
$form->select('module', '模块', true)->verify('required')->options(CatchAdmin::getModulesInfo());
|
||||
$form->text('route', '路由')->placeholder('请输入路由');
|
||||
$form->radio('method', '请求方法', true)->default(Permission::GET)->options([
|
||||
$form->radio('method', '请求方法', true)->default(Permissions::GET)->options([
|
||||
['value' => Permissions::GET, 'title' => 'get'],
|
||||
['value' => Permissions::POST, 'title' => 'post'],
|
||||
['value' => Permissions::PUT, 'title' => 'put'],
|
||||
['value' => Permissions::DELETE, 'title' => 'delete'],
|
||||
]);
|
||||
$form->text('permission_mark', '权限标识', true)->verify('required')->placeholder('请输入权限标识controller:action');
|
||||
$form->radio('type', '类型', true)->default(Permission::BTN_TYPE)->options([
|
||||
$form->radio('type', '类型', true)->default(Permissions::BTN_TYPE)->options([
|
||||
['value' => Permissions::MENU_TYPE, 'title' => '菜单'],
|
||||
['value' => Permissions::BTN_TYPE, 'title' => '按钮'],
|
||||
]);
|
||||
|
@ -4,9 +4,7 @@
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"order": 2,
|
||||
"services": [
|
||||
"catchAdmin\\permissions\\PermissionService"
|
||||
],
|
||||
"services": [],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": []
|
||||
|
Loading…
x
Reference in New Issue
Block a user