feat(settings): boutons Tester email/ntfy/IA + clés techniques masquées (partiel #80)

- Endpoints POST api/settings/{email,ntfy,ai}/test (Admin) :
  - email : envoi réel via EmailService vers l'expéditeur configuré
  - ntfy : SendTestAsync (nouvelle méthode INtfyService, retour HTTP 2xx)
  - ai : ping CodeProject.AI/Ollama via AiHealthCheck
- Client API : TestEmailAsync/TestNtfyAsync/TestAiAsync + record TestActionResult
- UI : boutons Tester dans NotificationSettingsSection (ntfy + email) et
  AiSettingsSection (moteurs IA) avec résultat inline
- AgentDetail : la clé brute n'est plus affichée (libellé global/surchargé)
- Tests bUnit : 3 nouveaux (POST par endpoint + affichage résultat) — 224 verts
This commit is contained in:
Arnaud Dartois committed 2026-08-12 11:50:47 +02:00
1 parent 574f242ff0
commit 85bfdac7ee
9 files changed
+304 -20

No files matched your search

@@ -249,6 +249,77 @@ public class SettingsController : ControllerBase
});
}
/// <summary>
/// Send a test email through the configured SMTP server (Admin only).
/// </summary>
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
[HttpPost("email/test")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> TestEmail(
[FromServices] IEmailService emailService,
CancellationToken ct)
{
var settings = await _mediator.Send(new GetSettingsQuery(), ct);
if (!settings.IsSuccess)
return StatusCode(settings.StatusCode ?? 400, new { error = settings.Error });
var fromAddress = settings.Data!.FirstOrDefault(s => s.Key == "email.fromaddress")?.Value;
if (string.IsNullOrWhiteSpace(fromAddress))
return BadRequest(new { error = "Adresse expéditrice non configurée (email.fromaddress)." });
try
{
await emailService.SendEmailAsync(fromAddress, "Heimdall — test de configuration",
"<h2>✅ Configuration email OK</h2><p>Ce message confirme que le serveur SMTP est joignable et que l'authentification fonctionne.</p>", ct);
return Ok(new { success = true, message = $"Email de test envoyé à {fromAddress}" });
}
catch (Exception ex)
{
return Ok(new { success = false, message = $"Échec de l'envoi : {ex.Message}" });
}
}
/// <summary>
/// Send a test notification through the configured ntfy server (Admin only).
/// </summary>
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
[HttpPost("ntfy/test")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
public async Task<IActionResult> TestNtfy(
[FromServices] INtfyService ntfyService,
[FromBody] TestNtfyRequest? request,
CancellationToken ct)
{
var topic = string.IsNullOrWhiteSpace(request?.Topic) ? "heimdall-test" : request.Topic;
var ok = await ntfyService.SendTestAsync(topic, "Heimdall — test de configuration",
"✅ Notification ntfy reçue : le serveur est joignable et le token est accepté.", ct);
return Ok(new { success = ok, message = ok
? $"Notification test envoyée sur le topic « {topic} »"
: "Échec de l'envoi ntfy (serveur injoignable ou rejet — voir les logs)." });
}
/// <summary>
/// Ping the configured AI backends (CodeProject.AI / Ollama) (Admin only).
/// </summary>
[Authorize(AuthenticationSchemes = "JwtBearer,Cookies", Policy = AppPermissions.AdminManage)]
[HttpPost("ai/test")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
public async Task<IActionResult> TestAi(
[FromServices] Heimdall.Infrastructure.HealthChecks.AiHealthCheck aiHealthCheck,
CancellationToken ct)
{
var result = await aiHealthCheck.CheckHealthAsync(null!, ct);
return Ok(new
{
success = result.Status == Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus.Healthy,
status = result.Status.ToString(),
message = result.Description,
});
}
public sealed record TestNtfyRequest(string? Topic);
/// <summary>
/// Broadcast a "ConfigReload" signal to all connected agents so they
/// re-fetch their full configuration (Admin only).