@@ -22,5 +22,6 @@ class DatabaseSeeder extends Seeder
|
||||
|
||||
$this->call(InvestMozReferenceSeeder::class);
|
||||
$this->call(LocalTestUserSeeder::class);
|
||||
$this->call(SampleManagerAccountsSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Creates local-only account examples for management UI and access-control exercises.
|
||||
* These accounts are deliberately unverified, have no MFA, and are not added to the
|
||||
* configured portal manager allowlist.
|
||||
*/
|
||||
class SampleManagerAccountsSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
if (! app()->environment(['local', 'testing'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (range(1, 10) as $number) {
|
||||
$suffix = str_pad((string) $number, 2, '0', STR_PAD_LEFT);
|
||||
|
||||
$user = User::firstOrCreate(
|
||||
['email' => "gestor{$suffix}@example.test"],
|
||||
[
|
||||
'name' => "Gestor de Exemplo {$suffix}",
|
||||
'password' => Str::random(48),
|
||||
],
|
||||
);
|
||||
|
||||
if ($user->wasRecentlyCreated) {
|
||||
$user->forceFill([
|
||||
'email_verified_at' => null,
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
'two_factor_confirmed_at' => null,
|
||||
])->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
|
||||
$records = $data['records'];
|
||||
|
||||
$actualCounts = is_array($records) ? array_count_values(array_column($records, 'location_type')) : [];
|
||||
$actualCounts = array_count_values(array_column($records, 'location_type'));
|
||||
ksort($actualCounts);
|
||||
$expectedCounts = self::EXPECTED_COUNTS;
|
||||
ksort($expectedCounts);
|
||||
@@ -41,7 +41,6 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
|| ! is_string($data['records_sha256'] ?? null)
|
||||
|| ! hash_equals(self::RECORDS_CHECKSUM, $data['records_sha256'])
|
||||
|| ! hash_equals(self::RECORDS_CHECKSUM, hash('sha256', json_encode($records, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR)))
|
||||
|| ! is_array($records)
|
||||
|| $actualCounts !== $expectedCounts) {
|
||||
throw new RuntimeException('Territory reference dataset failed its source or completeness checks.');
|
||||
}
|
||||
@@ -113,7 +112,7 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
return $counts;
|
||||
});
|
||||
|
||||
$this->command?->info(sprintf(
|
||||
$this->command->info(sprintf(
|
||||
'Referências territoriais: %d criadas, %d já existentes, %d classificadas como públicas.',
|
||||
$counts['created'],
|
||||
$counts['unchanged'],
|
||||
@@ -124,9 +123,16 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
/** @param array<string, mixed> $record
|
||||
* @param array<string, bool> $seen
|
||||
* @param array<string, string> $types
|
||||
*
|
||||
* @param-out array<string, bool> $seen
|
||||
* @param-out array<string, string> $types
|
||||
*/
|
||||
private function validateRecord(array $record, array &$seen, array &$types): void
|
||||
{
|
||||
$id = $record['id'] ?? null;
|
||||
if (! is_string($id) || $id === '') {
|
||||
throw new RuntimeException('Territory reference is missing a valid id.');
|
||||
}
|
||||
foreach (['id', 'name', 'location_type', 'code', 'source_code'] as $field) {
|
||||
if (! isset($record[$field]) || $record[$field] === '') {
|
||||
throw new RuntimeException('Territory reference is missing '.$field.'.');
|
||||
@@ -142,7 +148,7 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
'locality' => 'admin_post',
|
||||
];
|
||||
|
||||
if (! array_key_exists($type, $parentTypes) || isset($seen[$record['id']])) {
|
||||
if (! is_string($type) || ! array_key_exists($type, $parentTypes) || isset($seen[$id])) {
|
||||
throw new RuntimeException('Territory reference has an invalid type or duplicate ID.');
|
||||
}
|
||||
|
||||
@@ -152,11 +158,11 @@ class TerritoryReferenceSeeder extends Seeder
|
||||
if ($record['parent_id'] !== null) {
|
||||
throw new RuntimeException('Country reference cannot have a parent.');
|
||||
}
|
||||
} elseif (! $record['parent_id'] || ($types[$record['parent_id']] ?? null) !== $expectedParent) {
|
||||
throw new RuntimeException('Territory reference has a missing or invalid parent: '.$record['id']);
|
||||
} elseif (! is_string($record['parent_id'] ?? null) || ($types[$record['parent_id']] ?? null) !== $expectedParent) {
|
||||
throw new RuntimeException('Territory reference has a missing or invalid parent: '.$id);
|
||||
}
|
||||
|
||||
$seen[$record['id']] = true;
|
||||
$types[$record['id']] = $type;
|
||||
$seen[$id] = true;
|
||||
$types[$id] = $type;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user