AuditLogging module Username added to audit logs

pull/395/head
Yunus Emre Kalkan 7 years ago
parent a09c105e04
commit 3436176367

@ -12,6 +12,8 @@ namespace Volo.Abp.Auditing
{
public Guid? UserId { get; set; }
public string UserName { get; set; }
public Guid? TenantId { get; set; }
public Guid? ImpersonatorUserId { get; set; }
@ -58,7 +60,7 @@ namespace Volo.Abp.Auditing
var sb = new StringBuilder();
sb.AppendLine($"AUDIT LOG: [{HttpStatusCode?.ToString() ?? "---"}: {(HttpMethod ?? "-------").PadRight(7)}] {Url}");
sb.AppendLine($"- UserId : {UserId}");
sb.AppendLine($"- UserName - UserId : {UserName} - {UserId}");
sb.AppendLine($"- ClientIpAddress : {ClientIpAddress}");
sb.AppendLine($"- ExecutionDuration : {ExecutionDuration}");

@ -84,6 +84,7 @@ namespace Volo.Abp.Auditing
{
TenantId = CurrentTenant.Id,
UserId = CurrentUser.Id,
UserName = CurrentUser.UserName,
//ImpersonatorUserId = AbpSession.ImpersonatorUserId, //TODO: Impersonation system is not available yet!
//ImpersonatorTenantId = AbpSession.ImpersonatorTenantId,
ExecutionTime = Clock.Now

@ -15,5 +15,7 @@
public const int MaxUrlLength = 256;
public const int MaxHttpMethodLength = 16;
public const int MaxUserNameLength = 256;
}
}

@ -14,6 +14,8 @@ namespace Volo.Abp.AuditLogging
{
public virtual Guid? UserId { get; protected set; }
public virtual string UserName { get; protected set; }
public virtual Guid? TenantId { get; protected set; }
public virtual Guid? ImpersonatorUserId { get; protected set; }
@ -56,6 +58,7 @@ namespace Volo.Abp.AuditLogging
Id = guidGenerator.Create();
TenantId = auditInfo.TenantId;
UserId = auditInfo.UserId;
UserName = auditInfo.UserName;
ExecutionTime = auditInfo.ExecutionTime;
ExecutionDuration = auditInfo.ExecutionDuration;
ClientIpAddress = auditInfo.ClientIpAddress;

@ -14,6 +14,7 @@ namespace Volo.Abp.AuditLogging
string filter = null,
string httpMethod = null,
string url = null,
string userName = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = false);
}

@ -36,6 +36,7 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
b.Property(x => x.ImpersonatorTenantId).HasColumnName(nameof(AuditLog.ImpersonatorTenantId));
b.Property(x => x.ImpersonatorUserId).HasColumnName(nameof(AuditLog.ImpersonatorUserId));
b.Property(x => x.UserId).HasColumnName(nameof(AuditLog.UserId));
b.Property(x => x.UserName).HasMaxLength(AuditLogConsts.MaxUserNameLength).HasColumnName(nameof(AuditLog.UserName));
b.Property(x => x.TenantId).HasColumnName(nameof(AuditLog.TenantId));
b.HasMany<AuditLogAction>().WithOne().HasForeignKey(x => x.AuditLogId);

@ -24,14 +24,16 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
string filter = null,
string httpMethod = null,
string url = null,
string userName = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = false)
{
var query = DbSet.AsNoTracking()
.IncludeDetails(includeDetails)
.WhereIf(httpMethod != null, q => q.HttpMethod != null && q.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, q => q.Url != null && q.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(httpStatusCode != null && httpStatusCode > 0, q => q.HttpStatusCode == (int?)httpStatusCode);
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode);
var totalCount = await query.LongCountAsync();

@ -19,12 +19,13 @@ namespace Volo.Abp.AuditLogging.MongoDB
}
public async Task<Paging.PagedResult<AuditLog>> GetListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0, string filter = null,
string httpMethod = null, string url = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = false)
string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = false)
{
var query = GetMongoQueryable()
.WhereIf(httpMethod != null, q => q.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, q => q.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(httpStatusCode != null && httpStatusCode > 0, q => q.HttpStatusCode == (int?)httpStatusCode);
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode);
var totalCount = await query.As<IMongoQueryable<AuditLog>>().LongCountAsync();

Loading…
Cancel
Save