1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

implement audit log view in webfront

This commit is contained in:
RaidMax
2020-04-28 16:48:06 -05:00
parent 9a245c4db2
commit cc8756107f
11 changed files with 372 additions and 21 deletions

View File

@ -71,8 +71,8 @@ namespace SharedLibraryCore.Database
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// optionsBuilder.UseLoggerFactory(_loggerFactory)
// .EnableSensitiveDataLogging();
optionsBuilder.UseLoggerFactory(_loggerFactory)
.EnableSensitiveDataLogging();
if (string.IsNullOrEmpty(_ConnectionString))
{

View File

@ -0,0 +1,57 @@
using System;
namespace SharedLibraryCore.Dtos
{
/// <summary>
/// data transfer class for audit information
/// </summary>
public class AuditInfo
{
/// <summary>
/// name of the origin entity
/// </summary>
public string OriginName { get; set; }
/// <summary>
/// id of the origin entity
/// </summary>
public int OriginId { get; set; }
/// <summary>
/// name of the target entity
/// </summary>
public string TargetName { get; set; }
/// <summary>
/// id of the target entity
/// </summary>
public int? TargetId { get; set; }
/// <summary>
/// when the audit event occured
/// </summary>
public DateTime When { get; set; }
/// <summary>
/// what audit action occured
/// </summary>
public string Action { get; set; }
/// <summary>
/// additional comment data about the audit event
/// </summary>
public string Data { get; set; }
private string oldValue;
/// <summary>
/// previous value
/// </summary>
public string OldValue { get => oldValue ?? "--"; set => oldValue = value; }
private string newValue;
/// <summary>
/// new value
/// </summary>
public string NewValue { get => newValue ?? "--"; set => newValue = value; }
}
}

View File

@ -0,0 +1,34 @@
namespace SharedLibraryCore.Dtos
{
/// <summary>
/// pagination information holder class
/// </summary>
public class PaginationInfo
{
/// <summary>
/// how many items to skip
/// </summary>
public int Offset { get; set; }
/// <summary>
/// how many itesm to take
/// </summary>
public int Count { get; set; }
/// <summary>
/// filter query
/// </summary>
public string Filter { get; set; }
/// <summary>
/// direction of ordering
/// </summary>
public SortDirection Direction { get; set; } = SortDirection.Descending;
}
public enum SortDirection
{
Ascending,
Descending
}
}

View File

@ -0,0 +1,19 @@
using SharedLibraryCore.Dtos;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace SharedLibraryCore.Interfaces
{
/// <summary>
/// describes the capabilities of the audit info repository
/// </summary>
public interface IAuditInformationRepository
{
/// <summary>
/// retrieves a list of audit information for given pagination params
/// </summary>
/// <param name="paginationInfo">pagination info</param>
/// <returns></returns>
Task<IList<AuditInfo>> ListAuditInformation(PaginationInfo paginationInfo);
}
}

View File

@ -0,0 +1,55 @@
using Microsoft.EntityFrameworkCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SharedLibraryCore.Repositories
{
/// <summary>
/// implementation if IAuditInformationRepository
/// </summary>
public class AuditInformationRepository : IAuditInformationRepository
{
private readonly IDatabaseContextFactory _contextFactory;
public AuditInformationRepository(IDatabaseContextFactory contextFactory)
{
_contextFactory = contextFactory;
}
/// <inheritdoc/>
public async Task<IList<AuditInfo>> ListAuditInformation(PaginationInfo paginationInfo)
{
using (var ctx = _contextFactory.CreateContext(enableTracking: false))
{
var iqItems = (from change in ctx.EFChangeHistory
where change.TypeOfChange != Database.Models.EFChangeHistory.ChangeType.Ban
orderby change.TimeChanged descending
join originClient in ctx.Clients
on (change.ImpersonationEntityId ?? change.OriginEntityId) equals originClient.ClientId
join targetClient in ctx.Clients
on change.TargetEntityId equals targetClient.ClientId
into targetChange
from targetClient in targetChange.DefaultIfEmpty()
select new AuditInfo()
{
Action = change.TypeOfChange.ToString(),
OriginName = originClient.CurrentAlias.Name,
OriginId = originClient.ClientId,
TargetName = targetClient == null ? "" : targetClient.CurrentAlias.Name,
TargetId = targetClient == null ? new int?() : targetClient.ClientId,
When = change.TimeChanged,
Data = change.Comment,
OldValue = change.PreviousValue,
NewValue = change.CurrentValue
})
.Skip(paginationInfo.Offset)
.Take(paginationInfo.Count);
return await iqItems.ToListAsync();
}
}
}
}