- Se agregó autorización basada en permisos en múltiples Requests. - Nuevos Requests para motivos de cancelación y tags con validación y autorización. - Se añadieron métodos de roles al modelo User (isDeveloper, isAdmin, isPrimary). - Se actualizó el acceso a Telescope usando validación por roles. - Mejora en el manejo de excepciones de autorización. - Actualización de RoleSeeder con nuevas convenciones de permisos. - Actualización de dependencias (composer.lock).
67 lines
2.6 KiB
PHP
67 lines
2.6 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Middleware\SubstituteBindings;
|
|
use Illuminate\Session\Middleware\StartSession;
|
|
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
|
use Notsoweb\LaravelCore\Http\APIException;
|
|
use Spatie\Permission\Exceptions\UnauthorizedException;
|
|
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
|
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
api: __DIR__.'/../routes/api.php',
|
|
web: __DIR__.'/../routes/web.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withBroadcasting(
|
|
channels: __DIR__.'/../routes/channels.php',
|
|
attributes: ['middleware' => ['auth:api']]
|
|
)
|
|
->withMiddleware(function (Middleware $middleware) {
|
|
$middleware->group('api', [
|
|
StartSession::class,
|
|
SubstituteBindings::class,
|
|
]);
|
|
|
|
$middleware->validateCsrfTokens(except: [
|
|
'sanctum/csrf-cookie',
|
|
'user/*'
|
|
]);
|
|
|
|
$middleware->alias([
|
|
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
|
|
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
|
|
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
|
|
]);
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions) {
|
|
$exceptions->render(function (ServiceUnavailableHttpException $e, Request $request) {
|
|
if ($request->is('api/*')) {
|
|
return ApiResponse::SERVICE_UNAVAILABLE->response();
|
|
}
|
|
});
|
|
$exceptions->render(function (UnauthorizedException $e, Request $request) {
|
|
if ($request->is('api/*')) {
|
|
return ApiResponse::UNPROCESSABLE_CONTENT->response([
|
|
'message' => $e->getMessage()
|
|
]);
|
|
}
|
|
});
|
|
$exceptions->render(function (AccessDeniedHttpException $e, Request $request) {
|
|
if ($request->is('api/*')) {
|
|
return ApiResponse::UNPROCESSABLE_CONTENT->response([
|
|
'message' => __($e->getMessage())
|
|
]);
|
|
}
|
|
});
|
|
$exceptions->render(APIException::notFound(...));
|
|
$exceptions->render(APIException::unauthorized(...));
|
|
$exceptions->render(APIException::unprocessableContent(...));
|
|
})->create();
|