Skip to content

Commit

Permalink
Merge pull request #2523 from jxlwqq/master
Browse files Browse the repository at this point in the history
操作日志可按 Method 类型判断是否记录
  • Loading branch information
z-song authored Sep 19, 2018
2 parents 5385b41 + 6708e5b commit 1c185b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions config/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@

'enable' => true,

/*
* Only logging allowed methods in the list
*/
'allowed_methods' => ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'],

/*
* Routes that will not log to database.
*
Expand Down
21 changes: 20 additions & 1 deletion src/Middleware/LogOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,29 @@ public function handle(Request $request, \Closure $next)
protected function shouldLogOperation(Request $request)
{
return config('admin.operation_log.enable')
&& !$this->inExceptArray($request)
&& !$this->inExceptArray($request) && $this->inAllowedMethods($request->method())
&& Admin::user();
}


/**
* @param $method
*
* @return bool
*/
protected function inAllowedMethods($method) {
$allowed_methods = array_map('strtoupper', (array)config('admin.operation_log.allowed_methods'));
if (empty($allowed_methods)) {
return true;
} else {
if (in_array($method, $allowed_methods)) {
return true;
} else {
return false;
}
}
}

/**
* Determine if the request has a URI that should pass through CSRF verification.
*
Expand Down

0 comments on commit 1c185b8

Please sign in to comment.