up
This commit is contained in:
@@ -9,7 +9,7 @@ requireAdmin();
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
$roles = $db->fetchAll("SELECT id, name, slug, description, color, is_system, created_at FROM roles ORDER BY id ASC");
|
||||
$roles = $db->fetchAll("SELECT id, name, slug, description, color, home_page, is_system, created_at FROM roles ORDER BY id ASC");
|
||||
|
||||
foreach ($roles as &$role) {
|
||||
$mods = $db->fetchAll(
|
||||
|
||||
@@ -18,6 +18,7 @@ $name = trim($body['name'] ?? '');
|
||||
$slug = trim($body['slug'] ?? '');
|
||||
$description = trim($body['description'] ?? '');
|
||||
$color = trim($body['color'] ?? '#6c757d');
|
||||
$home_page = trim($body['home_page'] ?? '') ?: null;
|
||||
$modules = $body['modules'] ?? [];
|
||||
|
||||
if (!$name) jsonError('El nombre del rol es obligatorio');
|
||||
@@ -39,16 +40,16 @@ if ($id) {
|
||||
if (!$role) jsonError('Rol no encontrado', 404);
|
||||
|
||||
$db->query(
|
||||
"UPDATE roles SET name=?, slug=?, description=?, color=?, updated_at=NOW() WHERE id=?",
|
||||
[$name, $slug, $description, $color, $id]
|
||||
"UPDATE roles SET name=?, slug=?, description=?, color=?, home_page=?, updated_at=NOW() WHERE id=?",
|
||||
[$name, $slug, $description, $color, $home_page, $id]
|
||||
);
|
||||
// Reconstruir módulos solo si no es sistema, o siempre (admin puede editar módulos)
|
||||
$db->query("DELETE FROM role_modules WHERE role_id = ?", [$id]);
|
||||
} else {
|
||||
// Crear
|
||||
$db->query(
|
||||
"INSERT INTO roles (name, slug, description, color) VALUES (?,?,?,?)",
|
||||
[$name, $slug, $description, $color]
|
||||
"INSERT INTO roles (name, slug, description, color, home_page) VALUES (?,?,?,?,?)",
|
||||
[$name, $slug, $description, $color, $home_page]
|
||||
);
|
||||
$id = $db->lastInsertId();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user