diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs index f53479705a..5c7deb3d63 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditLogInfo.cs @@ -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}"); diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs index fd08a78d8c..ae579f4293 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditingHelper.cs @@ -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 diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs index f14eece49f..cc3a03ee0e 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain.Shared/Volo/Abp/AuditLogging/AuditLogConsts.cs @@ -15,5 +15,7 @@ public const int MaxUrlLength = 256; public const int MaxHttpMethodLength = 16; + + public const int MaxUserNameLength = 256; } } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs index 1b2f17a87a..a615d09c72 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/AuditLog.cs @@ -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; diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs index 2163b543d7..53b278ae5d 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs @@ -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); } diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs index 967250d976..820d098951 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingtDbContextModelBuilderExtensions.cs @@ -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().WithOne().HasForeignKey(x => x.AuditLogId); diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs index c778503ac8..c0bb68d835 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.EntityFrameworkCore/Volo/Abp/AuditLogging/EntityFrameworkCore/EfCoreAuditLogRepository.cs @@ -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(); diff --git a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs index 5b06681a45..8c2f831e73 100644 --- a/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs +++ b/modules/audit-logging/src/Volo.Abp.AuditLogging.MongoDB/Volo/Abp/AuditLogging/MongoDB/MongoAuditLogRepository.cs @@ -19,12 +19,13 @@ namespace Volo.Abp.AuditLogging.MongoDB } public async Task> 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>().LongCountAsync();