mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Añadidos permisos a tarifas, salvo metodo delete
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
use App\Models\Usuarios\GroupModel;
|
||||
use App\Models\Usuarios\PermisosModel;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
|
||||
if (!function_exists('generate_php_roles_constant')) {
|
||||
function generate_php_roles_constant()
|
||||
@ -94,3 +95,28 @@ if (!function_exists('generate_php_permissions_matrix_constant')) {
|
||||
|
||||
|
||||
|
||||
|
||||
if (!function_exists('checkPermission')) {
|
||||
/**
|
||||
* Checks if the user has the required permission and redirects accordingly.
|
||||
*
|
||||
* @param string $sectionPermission The permission to check.
|
||||
* @param string|null $redirectRoute The route to redirect to if the permission is not granted.
|
||||
* @return RedirectResponse|null Redirect response if the user does not have permission, null otherwise.
|
||||
*/
|
||||
function checkPermission(string $sectionPermission, string $redirectRoute = null)
|
||||
{
|
||||
$session = \Config\Services::session();
|
||||
$response = \Config\Services::response();
|
||||
|
||||
if (!auth()->user()->can($sectionPermission)) {
|
||||
$session->setFlashdata('errorMessage', "No tiene permisos de acceso");
|
||||
|
||||
$route = $redirectRoute ?? 'home';
|
||||
return $response->redirect(route_to($route));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user