2015-08-29 22:03:42 +08:00
|
|
|
<?php
|
|
|
|
|
2015-09-11 02:31:09 +08:00
|
|
|
namespace BookStack\Http\Middleware;
|
2015-08-29 22:03:42 +08:00
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class PermissionMiddleware
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
2021-06-26 23:23:15 +08:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @param $permission
|
|
|
|
*
|
2015-08-29 22:03:42 +08:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next, $permission)
|
|
|
|
{
|
|
|
|
if (!$request->user() || !$request->user()->can($permission)) {
|
2020-02-02 21:10:21 +08:00
|
|
|
session()->flash('error', trans('errors.permission'));
|
2021-06-26 23:23:15 +08:00
|
|
|
|
2015-08-29 22:03:42 +08:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|