- renombrar openspec/ a _openspec/ (carpeta auxiliar) - mover specs de features a changes/ - crear specs base: arquitectura-limpia, estandares-codigo, nomenclatura - migrar _planificacion/ con design-system y roi-theme-template - agregar especificacion recaptcha anti-spam (proposal, tasks, spec) - corregir rutas y referencias en todas las specs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4.5 KiB
4.5 KiB
Tasks: reCAPTCHA v3 Anti-Spam Protection
Fase 1: Especificación
- Crear proposal.md
- Crear tasks.md
- Crear spec.md con formato Gherkin
- Obtener aprobación del usuario
Fase 2: Implementación
2.1 Capa Domain (Contratos y Entidades)
- Crear
Shared/Domain/Contracts/RecaptchaValidatorInterface.phpinterface RecaptchaValidatorInterface { public function validate(string $token, string $action): RecaptchaResult; } - Crear
Shared/Domain/Entities/RecaptchaResult.phpfinal class RecaptchaResult { public function __construct( private bool $success, private float $score, private string $action, private array $errorCodes = [] ) {} public function isValid(float $threshold): bool; }
2.2 Capa Application (Servicios)
- Crear
Shared/Application/Services/RecaptchaValidationService.php- Orquestar validación
- Aplicar threshold configurable
- Logging de resultados
2.3 Capa Infrastructure (Implementación)
- Crear
Shared/Infrastructure/Services/GoogleRecaptchaValidator.php- Llamada HTTP a API de Google
- Manejo de errores y timeout
- Parseo de respuesta JSON
2.4 Schema y Admin UI
- Crear
Schemas/recaptcha-settings.json- Campos: is_enabled, site_key, secret_key, score_threshold, actions
- Sincronizar schema con BD:
wp roi-theme sync-component recaptcha-settings - Crear
Admin/RecaptchaSettings/Infrastructure/Ui/RecaptchaSettingsFormBuilder.php - Crear
Admin/RecaptchaSettings/Infrastructure/FieldMapping/RecaptchaSettingsFieldMapper.php - Registrar en
getComponents()del AdminDashboardRenderer - Registrar FieldMapper en FieldMapperRegistry
2.5 Integración Frontend
- Modificar
FooterRenderer.php- Agregar script de reCAPTCHA con site key
- Modificar form para incluir token hidden
- Modificar
ContactFormRenderer.php- Agregar script de reCAPTCHA con site key
- Modificar form para incluir token hidden
- Crear JS compartido para ejecutar reCAPTCHA y obtener token
2.6 Integración Backend
- Modificar
NewsletterAjaxHandler.php- Inyectar RecaptchaValidationService
- Validar token antes de procesar
- Retornar error si score bajo
- Modificar
ContactFormAjaxHandler.php- Inyectar RecaptchaValidationService
- Validar token antes de procesar
- Retornar error si score bajo
2.7 Registro DI
- Modificar
functions.php- Registrar RecaptchaValidatorInterface → GoogleRecaptchaValidator
- Registrar RecaptchaValidationService
Fase 3: Integración y Validación
3.1 Testing Manual
- Probar Newsletter con reCAPTCHA habilitado
- Probar Contact Form con reCAPTCHA habilitado
- Probar con reCAPTCHA deshabilitado (fallback)
- Probar cambio de threshold desde admin
- Verificar logging de intentos
3.2 Validación de Arquitectura
- Ejecutar
validate-architecture.php recaptcha-settings - Verificar cumplimiento Clean Architecture
- Verificar inyección de dependencias correcta
3.3 Documentación
- Actualizar CLAUDE.md si es necesario
- Documentar configuración en admin
Dependencias
| Tarea | Depende de |
|---|---|
| Application Service | Domain Contract |
| Infrastructure Service | Domain Contract |
| Admin FormBuilder | Schema JSON sincronizado |
| Frontend integration | Site Key configurado |
| Backend integration | Application Service + Infrastructure |
Estimación de Archivos
| Tipo | Cantidad |
|---|---|
| Nuevos | 7 |
| Modificados | 7 |
| Total | 14 |
Archivos Nuevos
Shared/Domain/Contracts/RecaptchaValidatorInterface.phpShared/Domain/Entities/RecaptchaResult.phpShared/Application/Services/RecaptchaValidationService.phpShared/Infrastructure/Services/GoogleRecaptchaValidator.phpSchemas/recaptcha-settings.jsonAdmin/RecaptchaSettings/Infrastructure/Ui/RecaptchaSettingsFormBuilder.phpAdmin/RecaptchaSettings/Infrastructure/FieldMapping/RecaptchaSettingsFieldMapper.php
Archivos a Modificar
Public/Footer/Infrastructure/Api/WordPress/NewsletterAjaxHandler.phpPublic/ContactForm/Infrastructure/Api/WordPress/ContactFormAjaxHandler.phpPublic/Footer/Infrastructure/Ui/FooterRenderer.phpPublic/ContactForm/Infrastructure/Ui/ContactFormRenderer.phpfunctions.phpAdmin/Infrastructure/Ui/AdminDashboardRenderer.phpAdmin/Shared/Infrastructure/FieldMapping/FieldMapperRegistry.php
Última actualización
2025-01-08