99 lines
3.9 KiB
PHP
Executable File
99 lines
3.9 KiB
PHP
Executable File
<?php
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Facades\URL;
|
|
use Illuminate\Support\Facades\View;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
// Spatie Permission (permessi/ruoli)
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton('db.schema', function ($app) {
|
|
$connection = $app['db']->connection();
|
|
|
|
if (class_exists(\Esign\DatabaseTrigger\Facades\Schema::class) && $connection->getDriverName() === 'mysql') {
|
|
return \Esign\DatabaseTrigger\Facades\Schema::getSchemaBuilder($connection);
|
|
}
|
|
|
|
return $connection->getSchemaBuilder();
|
|
});
|
|
|
|
if (interface_exists(\Laravel\Fortify\Contracts\VerifyEmailViewResponse::class)) {
|
|
$this->app->singleton(
|
|
\Laravel\Fortify\Contracts\VerifyEmailViewResponse::class,
|
|
\App\Http\Responses\FortifyVerifyEmailViewResponse::class
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
// For reverse-proxy HTTPS deployments (iPhone/Safari auth cookie compatibility).
|
|
if ((bool) env('APP_FORCE_HTTPS', false)) {
|
|
URL::forceScheme('https');
|
|
}
|
|
|
|
// View Composer per la sidebar
|
|
View::composer([
|
|
'components.menu.sidebar',
|
|
'components.menu.sidebar-netgescon',
|
|
'superadmin.dashboard',
|
|
'admin.dashboard',
|
|
], \App\Http\View\Composers\SidebarComposer::class);
|
|
|
|
// Helper per le impostazioni utente
|
|
if (! function_exists('userSetting')) {
|
|
function userSetting($key, $default = null)
|
|
{
|
|
return \App\Models\UserSetting::get($key, $default);
|
|
}
|
|
}
|
|
|
|
// Registra comandi Artisan applicativi quando in console
|
|
if ($this->app->runningInConsole()) {
|
|
$this->commands([
|
|
\App\Console\Commands\CodeQualityScan::class,
|
|
]);
|
|
}
|
|
|
|
// Bootstrap permessi base (idempotente): crea permessi e assegna a super-admin
|
|
try {
|
|
if (Schema::hasTable('permissions') && Schema::hasTable('roles') && Schema::hasTable('role_has_permissions')) {
|
|
// Crea permessi se mancanti
|
|
$pViewImport = Permission::findOrCreate('gescon-import.view');
|
|
$pExecImport = Permission::findOrCreate('gescon-import.execute');
|
|
$pViewContab = Permission::findOrCreate('contabilita-gescon.view');
|
|
// Permesso specifico per accedere/modificare la Configurazione di Gescon Import
|
|
$pConfigImport = Permission::findOrCreate('gescon-import.config');
|
|
// Permessi gestione utenti (pannello SuperAdmin)
|
|
$pViewUsers = Permission::findOrCreate('view-users');
|
|
$pCreateUsers = Permission::findOrCreate('create-users');
|
|
$pManageUsers = Permission::findOrCreate('manage-users');
|
|
$pImpersonateUsers = Permission::findOrCreate('impersonate-users');
|
|
|
|
// Assicura ruolo super-admin esiste e possiede tutti i permessi sensibili
|
|
$super = Role::findOrCreate('super-admin');
|
|
$super->givePermissionTo([$pViewImport, $pExecImport, $pConfigImport, $pViewContab, $pViewUsers, $pCreateUsers, $pManageUsers, $pImpersonateUsers]);
|
|
|
|
// Nota: ruolo 'amministratore' NON riceve questi permessi di default
|
|
Role::findOrCreate('amministratore');
|
|
Role::findOrCreate('collaboratore');
|
|
}
|
|
} catch (\Throwable $e) {
|
|
// Silenzia in bootstrap (es. durante installazione senza DB)
|
|
}
|
|
}
|
|
}
|