From 8ff56d3d78897a780ad1deb87242c3fe4c236272 Mon Sep 17 00:00:00 2001 From: Soporte ZH Consultores Date: Thu, 4 Jun 2026 21:31:02 -0500 Subject: [PATCH] =?UTF-8?q?refactor(users):=20eliminar=20columna=20orden,?= =?UTF-8?q?=20listar=20alfab=C3=A9ticamente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Migración 012: ALTER TABLE users DROP COLUMN orden - Lookups: abogadoNames y allUsers ordenan por name ASC - API admin: create/update_user dejan de leer/escribir orden - UI admin: removida la columna "Orden" de la tabla y el input "Orden" del modal de usuario --- public/admin/api.php | 18 +++++++----------- sql/012_drop_users_orden.sql | 7 +++++++ src/Lookups.php | 7 +++---- views/admin.html | 17 ++--------------- 4 files changed, 19 insertions(+), 30 deletions(-) create mode 100644 sql/012_drop_users_orden.sql diff --git a/public/admin/api.php b/public/admin/api.php index 98c3034..d47c4c8 100644 --- a/public/admin/api.php +++ b/public/admin/api.php @@ -46,7 +46,6 @@ try { $name = trim((string)($b['name'] ?? '')); $role = in_array(($b['role'] ?? ''), ROLES, true) ? $b['role'] : 'usuario'; $activo = (int)($b['activo'] ?? 1) === 1 ? 1 : 0; - $orden = (int)($b['orden'] ?? 0); // Solo admins pueden crear nuevos admins if ($role === 'admin' && !Auth::isAdmin()) { @@ -58,21 +57,20 @@ try { if ($exists->fetch()) err('Ya existe un usuario con ese email', 409); $ins = $pdo->prepare( - 'INSERT INTO users (email, name, role, activo, orden, first_seen_at, last_login_at) - VALUES (:email, :name, :role, :activo, :orden, NULL, NULL)' + 'INSERT INTO users (email, name, role, activo, first_seen_at, last_login_at) + VALUES (:email, :name, :role, :activo, NULL, NULL)' ); $ins->execute([ ':email' => $email, ':name' => $name, ':role' => $role, - ':activo' => $activo, ':orden' => $orden, + ':activo' => $activo, ]); $id = (int)$pdo->lastInsertId(); - $sel = $pdo->prepare('SELECT id, email, name, role, activo, orden, first_seen_at, last_login_at FROM users WHERE id = :id'); + $sel = $pdo->prepare('SELECT id, email, name, role, activo, first_seen_at, last_login_at FROM users WHERE id = :id'); $sel->execute([':id' => $id]); $row = $sel->fetch(); $row['id'] = (int)$row['id']; $row['activo'] = (int)$row['activo']; - $row['orden'] = (int)$row['orden']; AuditLog::log('admin', 'create_user', 'user', (string)$id, $email, ['role'=>$role, 'name'=>$name]); ok($row); } @@ -116,25 +114,23 @@ try { } $name = trim((string)($b['name'] ?? '')); - $orden = (int)($b['orden'] ?? 0); $upd = $pdo->prepare( 'UPDATE users SET email = :email, name = :name, role = :role, - activo = :activo, orden = :orden + activo = :activo WHERE id = :id' ); $upd->execute([ ':email' => $newEmail, ':name' => $name, ':role' => $newRole, - ':activo' => $newActivo, ':orden' => $orden, + ':activo' => $newActivo, ':id' => $id, ]); - $sel = $pdo->prepare('SELECT id, email, name, role, activo, orden, first_seen_at, last_login_at FROM users WHERE id = :id'); + $sel = $pdo->prepare('SELECT id, email, name, role, activo, first_seen_at, last_login_at FROM users WHERE id = :id'); $sel->execute([':id' => $id]); $row = $sel->fetch(); $row['id'] = (int)$row['id']; $row['activo'] = (int)$row['activo']; - $row['orden'] = (int)$row['orden']; $diff = []; if ($existing['role'] !== $newRole) $diff['role'] = ['from'=>$existing['role'], 'to'=>$newRole]; if ((int)$existing['activo'] !== $newActivo) $diff['activo'] = ['from'=>(int)$existing['activo'], 'to'=>$newActivo]; diff --git a/sql/012_drop_users_orden.sql b/sql/012_drop_users_orden.sql new file mode 100644 index 0000000..9161550 --- /dev/null +++ b/sql/012_drop_users_orden.sql @@ -0,0 +1,7 @@ +-- ============================================================ +-- Donna — Schema 012: eliminar columna users.orden +-- ============================================================ +-- Decisión: simplificar. Las listas se ordenan alfabéticamente +-- por nombre. No hay necesidad de un orden manual. + +ALTER TABLE users DROP COLUMN IF EXISTS orden; diff --git a/src/Lookups.php b/src/Lookups.php index 71b3fc5..3f2fa2d 100644 --- a/src/Lookups.php +++ b/src/Lookups.php @@ -19,7 +19,7 @@ final class Lookups { WHERE activo = 1 AND role IN ('socio','abogado') AND name != '' - ORDER BY orden ASC, name ASC" + ORDER BY name ASC" )->fetchAll(); return array_map(fn($r) => $r['name'], $rows); } @@ -43,15 +43,14 @@ final class Lookups { * Si $includeAdmins es false, oculta el rol admin (uso para socios). */ public static function allUsers(bool $includeAdmins = true): array { - $sql = "SELECT id, email, name, role, activo, orden, first_seen_at, last_login_at + $sql = "SELECT id, email, name, role, activo, first_seen_at, last_login_at FROM users"; if (!$includeAdmins) $sql .= " WHERE role != 'admin'"; - $sql .= " ORDER BY FIELD(role,'admin','socio','abogado','usuario'), name ASC, email ASC"; + $sql .= " ORDER BY name ASC, email ASC"; $rows = Db::pdo()->query($sql)->fetchAll(); foreach ($rows as &$r) { $r['id'] = (int)$r['id']; $r['activo'] = (int)$r['activo']; - $r['orden'] = (int)$r['orden']; } return $rows; } diff --git a/views/admin.html b/views/admin.html index dad4c44..a3257f1 100644 --- a/views/admin.html +++ b/views/admin.html @@ -234,7 +234,6 @@ tr.is-me td { background:#FFFBEB; font-weight:500; } Nombre completo Rol Activo - Orden Último login @@ -339,16 +338,8 @@ tr.is-me td { background:#FFFBEB; font-weight:500; } -
-
- - -
Para ordenar el dropdown manualmente.
-
-
- - -
+
+