feat(authorization): refactor role management to use RoleCode enum, update migrations, seeders, and tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
@@ -13,21 +14,14 @@ return new class extends Migration
|
||||
|
||||
DB::table('roles')->insertOrIgnore([
|
||||
[
|
||||
'codigo' => 'admin',
|
||||
'codigo' => RoleCode::Admin->value,
|
||||
'nombre' => 'Administrador general',
|
||||
'descripcion' => 'Administra la plataforma y todos sus tenants.',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
[
|
||||
'codigo' => 'tenant_admin',
|
||||
'nombre' => 'Administrador del tenant',
|
||||
'descripcion' => 'Administra la operación de su propio tenant.',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
[
|
||||
'codigo' => 'user',
|
||||
'codigo' => RoleCode::User->value,
|
||||
'nombre' => 'Usuario',
|
||||
'descripcion' => 'Cliente final limitado a sus propios datos y operaciones.',
|
||||
'created_at' => $now,
|
||||
@@ -36,7 +30,7 @@ return new class extends Migration
|
||||
]);
|
||||
|
||||
Schema::table('users', function (Blueprint $table): void {
|
||||
$table->string('rol_codigo')->default('user')->after('id');
|
||||
$table->string('rol_codigo')->default(RoleCode::User->value)->after('id');
|
||||
$table->string('tenant_codigo')->nullable()->after('rol_codigo');
|
||||
|
||||
$table->foreign('rol_codigo')
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const REMOVED_ROLE_CODE = 'tenant_admin';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('users')
|
||||
->where('rol_codigo', self::REMOVED_ROLE_CODE)
|
||||
->update([
|
||||
'rol_codigo' => RoleCode::User->value,
|
||||
'tenant_codigo' => null,
|
||||
]);
|
||||
|
||||
DB::table('roles')
|
||||
->where('codigo', self::REMOVED_ROLE_CODE)
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::table('roles')->insertOrIgnore([
|
||||
'codigo' => self::REMOVED_ROLE_CODE,
|
||||
'nombre' => 'Administrador del tenant',
|
||||
'descripcion' => 'Administra la operación de su propio tenant.',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user