@page "/audit-logs"
@attribute [Authorize(Policy = "Admin.Manage")]
@layout MainLayout
@inject HeimdallApiClient Api
@inject ISnackbar Snackbar
Journal d'audit
@if (_loading)
{
}
else if (_error)
{
Erreur lors du chargement du journal d'audit.
Réessayer
}
else
{
Date
Utilisateur
Action
Type
Ressource
IP
@context.Timestamp.ToString("g")
@(context.UserEmail ?? "-")
@context.Action
@context.ResourceType
@context.ResourceId?[..Math.Min(8, context.ResourceId?.Length ?? 0)]
@(context.IpAddress ?? "-")
Aucune entrée d'audit
Les actions d'administration seront journalisées ici.
Page @_page sur @_totalPages (@_total entrées)
← Précédent
Suivant →
}
@code {
private IReadOnlyList? _logs;
private bool _loading = true;
private bool _error;
private int _page = 1;
private int _totalPages = 1;
private int _total;
private string? _filterResourceType;
private string? _filterAction;
protected override async Task OnInitializedAsync() => await LoadLogs();
private async Task LoadLogs()
{
_loading = true;
_error = false;
try
{
var result = await Api.GetAuditLogsAsync(_filterResourceType, _filterAction, _page);
if (result is not null)
{
_logs = result.Items;
_total = result.TotalCount;
_totalPages = Math.Max(1, (int)Math.Ceiling(result.TotalCount / (double)result.PageSize));
}
}
catch (Exception ex)
{
_error = true;
Snackbar.Add($"Erreur : {ex.Message}", Severity.Error);
}
finally { _loading = false; }
}
private async Task GoToPage(int p) { _page = p; await LoadLogs(); }
private async Task ApplyFilters() { _page = 1; await LoadLogs(); }
private async Task ResetFilters() { _filterResourceType = null; _filterAction = null; _page = 1; await LoadLogs(); }
private static Color GetActionColor(string action) => action switch
{
"Site.Created" or "UserCreated" or "Group.Created" => Color.Success,
"UserRolesUpdated" or "UserPasswordReset" or "Group.Updated" => Color.Warning,
"UserLocked" => Color.Error,
"UserUnlocked" => Color.Info,
_ => Color.Default
};
}