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

@@ -0,0 +1,54 @@
<?php
namespace App\Console\Commands;
use App\Actions\PurgeUserAction;
use App\Models\User;
use Illuminate\Console\Command;
/**
* Anonimizza (GDPR) gli utenti soft-deleted oltre la retention, riassegnandone
* i contenuti all'utente di sistema. Idempotente, pensato per esecuzione
* schedulata giornaliera (vedi routes/console.php).
*/
class PurgeAnonymizableUsers extends Command
{
protected $signature = 'users:purge
{--days=30 : Days kept in the trash before anonymization}
{--dry-run : Show the affected users without anonymizing}';
protected $description = 'Anonymize users deleted beyond the retention window (GDPR right to be forgotten)';
public function handle(PurgeUserAction $purge): int
{
$days = (int) $this->option('days');
$dryRun = (bool) $this->option('dry-run');
$users = User::onlyTrashed()
->where('is_system', false)
->whereNull('anonymized_at')
->where('deleted_at', '<=', now()->subDays($days))
->get();
if ($users->isEmpty()) {
$this->info('No users to anonymize.');
return self::SUCCESS;
}
foreach ($users as $user) {
if ($dryRun) {
$this->line(sprintf(' [dry-run] #%d %s', $user->id, $user->email));
continue;
}
$purge->execute($user);
$this->line(sprintf(' ✓ anonymized user #%d', $user->id));
}
$this->info(($dryRun ? '[dry-run] ' : '').'Processed users: '.$users->count());
return self::SUCCESS;
}
}