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;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
|
|
|
|
|
|
|
class PermissionMiddleware
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @param $permission
|
|
|
|
* @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'));
|
2015-08-29 10:03:42 -04:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|