auth tests

This commit is contained in:
Giuseppe Naponiello
2026-06-22 14:31:44 +02:00
parent 34a8ebc6fb
commit cc4e174880
75 changed files with 4679 additions and 168 deletions

View File

@@ -2,7 +2,6 @@
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
@@ -11,15 +10,14 @@ class DatabaseSeeder extends Seeder
use WithoutModelEvents;
/**
* Seed the application's database.
* Seed dell'applicazione. L'ordine conta: i ruoli prima dell'utente di
* sistema (che richiede il ruolo Admin).
*/
public function run(): void
{
// User::factory(10)->create();
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
$this->call([
UserRoleSeeder::class,
SystemUserSeeder::class,
]);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Database\Seeders;
use App\Models\Lists\UserRole;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* Crea l'utente di sistema: riceve i contenuti riassegnati dagli utenti
* cancellati (flusso GDPR / oblio) e non è eliminabile accessibile
* (password casuale, nessun login previsto). Idempotente.
*
* Dipende da UserRoleSeeder (serve il ruolo Admin).
*/
class SystemUserSeeder extends Seeder
{
public const EMAIL = 'system@dyncoll.local';
public function run(): void
{
$adminRoleId = UserRole::where('name', UserRole::ADMIN)->value('id');
User::updateOrCreate(
['email' => self::EMAIL],
[
'name' => 'Dyncoll System',
'password' => Hash::make(Str::random(60)),
'role_id' => $adminRoleId,
'is_system' => true,
'must_change_password' => false,
'email_verified_at' => now(),
'two_factor_setup_completed_at' => now(),
]
);
$this->command?->info('✅ System user ready: '.self::EMAIL);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Database\Seeders;
use App\Models\Lists\UserRole;
use Illuminate\Database\Seeder;
class UserRoleSeeder extends Seeder
{
/**
* Ruoli applicativi di base. Idempotente.
* (description in inglese: lingua ufficiale dell'applicazione.)
*/
public function run(): void
{
UserRole::updateOrCreate(
['name' => UserRole::ADMIN],
['description' => 'Full access to all features.'
.' Manages users, configurations and global data supervision.'
.' Can create, read, update and delete any record.']
);
UserRole::updateOrCreate(
['name' => UserRole::SUPERVISOR],
['description' => 'Limited access to certain features.'
.' Can manage users but not administrators.'
.' Can create, read, update and delete both own and other users\' records.']
);
UserRole::updateOrCreate(
['name' => UserRole::USER],
['description' => 'Day-to-day operational use. Can access all records'
.' and create new ones, but can only update or delete their own.']
);
UserRole::updateOrCreate(
['name' => UserRole::GUEST],
['description' => 'Very limited access. Can only view information'
.' not publicly available, with no editing capabilities.']
);
}
}