/** * @test **/ public function GetsPermFromCurrentRoute() { $config_arr = $this->mockConfig(); Route::shouldReceive('currentRouteName')->andReturn("route2"); $helper = new FileRouteHelper(); $perm = $helper->getPermFromCurrentRoute(); $this->assertEquals($config_arr[1]["permissions"], $perm); }
Route::filter('logged', function ($request, $response, $custom_url = null) { $redirect_url = $custom_url ?: '/login'; if (!App::make('authenticator')->check()) { return Redirect::to($redirect_url); } }); /* |-------------------------------------------------------------------------- | Permission Filters |-------------------------------------------------------------------------- | | Check that the current user is logged in and has a the permission corresponding to the config menu file | */ Route::filter('can_see', function () { $route_helper = new FileRouteHelper(); if (!$route_helper->hasPermForRoute(Route::currentRouteName())) { App::abort('401'); } }); /* * Check that the user has one of the permission given */ Route::filter('has_perm', function () { $permissions = array_slice(func_get_args(), 2); $authentication_helper = App::make('authentication_helper'); if (!$authentication_helper->hasPermission($permissions)) { App::abort('401'); } }); /*