Primer commit del sistema separado falta mejorar mucho
This commit is contained in:
64
telegram/api/templates/delete.php
Executable file
64
telegram/api/templates/delete.php
Executable file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* API - Eliminar plantilla Telegram
|
||||
*/
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
||||
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
||||
require_once __DIR__ . '/../../../shared/database/connection.php';
|
||||
|
||||
// Verificar autenticación
|
||||
if (!isAuthenticated()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar permiso
|
||||
if (!hasPermission('manage_templates', 'telegram')) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'No tienes permiso para eliminar plantillas de Telegram.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
jsonResponse(['success' => false, 'error' => 'Método no permitido'], 405);
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($input['id'])) {
|
||||
jsonResponse(['success' => false, 'error' => 'ID no proporcionado'], 400);
|
||||
}
|
||||
|
||||
try {
|
||||
$db = getDB();
|
||||
|
||||
// Verificar que la plantilla existe
|
||||
$stmt = $db->prepare("SELECT * FROM plantillas_telegram WHERE id = ?");
|
||||
$stmt->execute([$input['id']]);
|
||||
$plantilla = $stmt->fetch();
|
||||
|
||||
if (!$plantilla) {
|
||||
jsonResponse(['success' => false, 'error' => 'Plantilla no encontrada'], 404);
|
||||
}
|
||||
|
||||
// Verificar permisos (admin o creador)
|
||||
if ($userData->rol !== 'Admin' && $plantilla['usuario_id'] != $userData->userId) {
|
||||
jsonResponse(['success' => false, 'error' => 'No tiene permisos para eliminar esta plantilla'], 403);
|
||||
}
|
||||
|
||||
// Eliminar plantilla
|
||||
$stmt = $db->prepare("DELETE FROM plantillas_telegram WHERE id = ?");
|
||||
$stmt->execute([$input['id']]);
|
||||
|
||||
logToFile('telegram/templates.log', "Plantilla eliminada: ID={$input['id']}, Usuario={$userData->username}");
|
||||
|
||||
jsonResponse(['success' => true, 'message' => 'Plantilla eliminada correctamente']);
|
||||
|
||||
} catch (Exception $e) {
|
||||
logToFile('telegram/errors.log', "Error eliminando plantilla: " . $e->getMessage(), 'ERROR');
|
||||
jsonResponse(['success' => false, 'error' => 'Error del servidor'], 500);
|
||||
}
|
||||
Reference in New Issue
Block a user