feat(authorization): refactor role management to use RoleCode enum, update migrations, seeders, and tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Domains\Auth\Models;
|
||||
|
||||
use App\Domains\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Authorization\Models\Role;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Database\Factories\UserFactory;
|
||||
@@ -13,7 +14,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use LogicException;
|
||||
|
||||
#[Fillable(['nombre_apellido', 'email', 'password', 'dni', 'telefono', 'google_id', 'rol_codigo', 'tenant_codigo'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
@@ -23,7 +23,7 @@ class User extends Authenticatable
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
protected $attributes = [
|
||||
'rol_codigo' => 'user',
|
||||
'rol_codigo' => RoleCode::User->value,
|
||||
];
|
||||
|
||||
protected static function newFactory(): UserFactory
|
||||
@@ -31,20 +31,6 @@ class User extends Authenticatable
|
||||
return UserFactory::new();
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saving(function (User $user): void {
|
||||
$hasTenant = $user->tenant_codigo !== null;
|
||||
$isTenantAdmin = $user->rol_codigo === 'tenant_admin';
|
||||
|
||||
if ($hasTenant !== $isTenantAdmin) {
|
||||
throw new LogicException(
|
||||
'tenant_codigo debe estar informado únicamente para usuarios con rol tenant_admin.'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** @return HasMany<ResetPasswordAttempt, $this> */
|
||||
public function resetPasswordAttempts(): HasMany
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user