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

@@ -149,8 +149,8 @@ else
<MudText Typo="Typo.body1" Class="font-weight-medium settings-label">
@(setting.Description ?? HumanizeAgentKey(setting.Key))
</MudText>
<MudText Typo="Typo.body2" Color="Color.Secondary" Class="settings-key">
@setting.Key
<MudText Typo="Typo.caption" Color="Color.Secondary">
@(overridden ? "Valeur surchargée pour cet agent" : "Valeur globale appliquée")
</MudText>
</div>
@if (overridden)
@@ -36,10 +36,25 @@
HelperText="Défaut global appliqué aux agents. Une modification nécessite le rechargement de la configuration des agents." />
</MudItem>
</MudGrid>
<div class="d-flex align-center mt-3">
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Radar"
OnClick="TestAiAsync" Disabled="@_testing">
@(_testing ? "Test en cours…" : "Tester les moteurs IA")
</MudButton>
</div>
@if (_testResult is not null)
{
<MudAlert Severity="@(_testResult.Success ? Severity.Success : Severity.Warning)" Class="mt-3" Variant="Variant.Outlined">
<strong>@_testResult.Status</strong> — @_testResult.Message
</MudAlert>
}
</MudPaper>
@code {
private List<AppSettingItem> _settings = [];
private bool _testing;
private TestActionResult? _testResult;
protected override async Task OnInitializedAsync()
{
@@ -60,6 +75,24 @@
private Task OnOllamaUrlChanged(string v) => SaveValueAsync("ai.ollamaurl", v);
private Task OnDetectionEnabledChanged(bool v) => SaveValueAsync("ai.detection.enabled", v ? "true" : "false");
private async Task TestAiAsync()
{
_testing = true;
_testResult = null;
try
{
_testResult = await Api.TestAiAsync() ?? new TestActionResult(false, "Test impossible (API indisponible).");
}
catch (Exception ex)
{
_testResult = new TestActionResult(false, $"Test impossible : {ex.Message}");
}
finally
{
_testing = false;
}
}
private async Task SaveValueAsync(string key, string? value)
{
value ??= string.Empty;
@@ -82,10 +82,29 @@
HelperText="Active le chiffrement TLS lors de la connexion SMTP." />
</MudItem>
</MudGrid>
<div class="d-flex align-center mt-3">
<MudButton Variant="Variant.Outlined" Color="Color.Info" StartIcon="@Icons.Material.Filled.Send"
OnClick="TestNtfyAsync" Disabled="@_testing">
@(_testing ? "Test en cours…" : "Tester ntfy")
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Info" Class="ml-2" StartIcon="@Icons.Material.Filled.Email"
OnClick="TestEmailAsync" Disabled="@_testing">
@(_testing ? "Test en cours…" : "Tester l'envoi email")
</MudButton>
</div>
@if (_testResult is not null)
{
<MudAlert Severity="@(_testResult.Success ? Severity.Success : Severity.Error)" Class="mt-3" Variant="Variant.Outlined">
@_testResult.Message
</MudAlert>
}
</MudPaper>
@code {
private List<AppSettingItem> _settings = [];
private bool _testing;
private TestActionResult? _testResult;
protected override async Task OnInitializedAsync()
{
@@ -121,6 +140,42 @@
private Task OnPasswordChanged(string v) => SaveValueAsync("email.password", v);
private Task OnUseSslChanged(bool v) => SaveValueAsync("email.usessl", v ? "true" : "false");
private async Task TestNtfyAsync()
{
_testing = true;
_testResult = null;
try
{
_testResult = await Api.TestNtfyAsync() ?? new TestActionResult(false, "Test impossible (API indisponible).");
}
catch (Exception ex)
{
_testResult = new TestActionResult(false, $"Test impossible : {ex.Message}");
}
finally
{
_testing = false;
}
}
private async Task TestEmailAsync()
{
_testing = true;
_testResult = null;
try
{
_testResult = await Api.TestEmailAsync() ?? new TestActionResult(false, "Test impossible (API indisponible).");
}
catch (Exception ex)
{
_testResult = new TestActionResult(false, $"Test impossible : {ex.Message}");
}
finally
{
_testing = false;
}
}
private async Task SaveValueAsync(string key, string? value)
{
value ??= string.Empty;