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

@@ -30,24 +30,7 @@ public class NtfyService : INtfyService
{
try
{
var (baseUrl, authToken) = await ResolveConfigAsync(ct).ConfigureAwait(false);
var client = _httpClientFactory.CreateClient("Ntfy");
var requestUrl = $"{baseUrl.TrimEnd('/')}/{topic}";
var payload = new { topic, title, message, priority };
var json = JsonSerializer.Serialize(payload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
if (!string.IsNullOrEmpty(authToken))
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", authToken);
var response = await client.PostAsync(requestUrl, content, ct).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
var body = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
_logger.LogWarning("ntfy returned {StatusCode} for topic {Topic}: {Body}", response.StatusCode, topic, body);
}
await SendCoreAsync(topic, title, message, priority, ct).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -55,6 +38,42 @@ public class NtfyService : INtfyService
}
}
public async Task<bool> SendTestAsync(string topic, string title, string message, CancellationToken ct = default)
{
try
{
var response = await SendCoreAsync(topic, title, message, 4, ct).ConfigureAwait(false);
if (!response.IsSuccessStatusCode)
{
var body = await response.Content.ReadAsStringAsync(ct).ConfigureAwait(false);
_logger.LogWarning("ntfy test returned {StatusCode} for topic {Topic}: {Body}", response.StatusCode, topic, body);
}
return response.IsSuccessStatusCode;
}
catch (Exception ex)
{
_logger.LogError(ex, "ntfy test failed for topic {Topic}", topic);
return false;
}
}
private async Task<HttpResponseMessage> SendCoreAsync(string topic, string title, string message, int priority, CancellationToken ct)
{
var (baseUrl, authToken) = await ResolveConfigAsync(ct).ConfigureAwait(false);
var client = _httpClientFactory.CreateClient("Ntfy");
var requestUrl = $"{baseUrl.TrimEnd('/')}/{topic}";
var payload = new { topic, title, message, priority };
var json = JsonSerializer.Serialize(payload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
if (!string.IsNullOrEmpty(authToken))
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", authToken);
return await client.PostAsync(requestUrl, content, ct).ConfigureAwait(false);
}
/// <summary>
/// Source de vérité : AppSettings en base (ntfy.*), avec fallback
/// config/appsettings puis env (migration douce, ticket #80). Relu à