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