refactor:重构审计日志模块,完善用户数据权限
This commit is contained in:
@@ -96,6 +96,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.TenantManageme
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yi.Framework.TenantManagement.Domain", "module\tenant-management\Yi.Framework.TenantManagement.Domain\Yi.Framework.TenantManagement.Domain.csproj", "{54D8E2BC-591C-4344-A58E-874D49C00B41}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AuditLogging.Domain", "module\audit-logging\Yi.Framework.AuditLogging.Domain\Yi.Framework.AuditLogging.Domain.csproj", "{EFD13211-17B5-400A-B99A-9F6F4E520C1E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yi.Framework.AuditLogging.Domain.Shared", "module\audit-logging\Yi.Framework.AuditLogging.Domain.Shared\Yi.Framework.AuditLogging.Domain.Shared.csproj", "{9C8C3C53-3DCE-4516-867E-228858E61B26}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -238,6 +242,14 @@ Global
|
||||
{54D8E2BC-591C-4344-A58E-874D49C00B41}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{54D8E2BC-591C-4344-A58E-874D49C00B41}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{54D8E2BC-591C-4344-A58E-874D49C00B41}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EFD13211-17B5-400A-B99A-9F6F4E520C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EFD13211-17B5-400A-B99A-9F6F4E520C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EFD13211-17B5-400A-B99A-9F6F4E520C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EFD13211-17B5-400A-B99A-9F6F4E520C1E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C8C3C53-3DCE-4516-867E-228858E61B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C8C3C53-3DCE-4516-867E-228858E61B26}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C8C3C53-3DCE-4516-867E-228858E61B26}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C8C3C53-3DCE-4516-867E-228858E61B26}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -281,6 +293,8 @@ Global
|
||||
{499A8C71-7892-42D0-A77E-48756E1EFF16} = {2317227D-7796-4E7B-BEDB-7CD1CAE7B853}
|
||||
{FA5BBAA1-08DC-472F-BB2C-5314E59D1556} = {499A8C71-7892-42D0-A77E-48756E1EFF16}
|
||||
{54D8E2BC-591C-4344-A58E-874D49C00B41} = {499A8C71-7892-42D0-A77E-48756E1EFF16}
|
||||
{EFD13211-17B5-400A-B99A-9F6F4E520C1E} = {73CCF2C4-B9FD-44AB-8D4B-0A421805B094}
|
||||
{9C8C3C53-3DCE-4516-867E-228858E61B26} = {73CCF2C4-B9FD-44AB-8D4B-0A421805B094}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {23D6FBC9-C970-4641-BC1E-2AEA59F51C18}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
public class AuditLogActionConsts
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value: 256
|
||||
/// </summary>
|
||||
public static int MaxServiceNameLength { get; set; } = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 128
|
||||
/// </summary>
|
||||
public static int MaxMethodNameLength { get; set; } = 128;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 2000
|
||||
/// </summary>
|
||||
public static int MaxParametersLength { get; set; } = 2000;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
public static class AuditLogConsts
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value: 96
|
||||
/// </summary>
|
||||
public static int MaxApplicationNameLength { get; set; } = 96;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 64
|
||||
/// </summary>
|
||||
public static int MaxClientIpAddressLength { get; set; } = 64;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 128
|
||||
/// </summary>
|
||||
public static int MaxClientNameLength { get; set; } = 128;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 64
|
||||
/// </summary>
|
||||
public static int MaxClientIdLength { get; set; } = 64;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 64
|
||||
/// </summary>
|
||||
public static int MaxCorrelationIdLength { get; set; } = 64;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 512
|
||||
/// </summary>
|
||||
public static int MaxBrowserInfoLength { get; set; } = 512;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 256
|
||||
/// </summary>
|
||||
public static int MaxCommentsLength { get; set; } = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 256
|
||||
/// </summary>
|
||||
public static int MaxUrlLength { get; set; } = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 16
|
||||
/// </summary>
|
||||
public static int MaxHttpMethodLength { get; set; } = 16;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 256
|
||||
/// </summary>
|
||||
public static int MaxUserNameLength { get; set; } = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 64
|
||||
/// </summary>
|
||||
public static int MaxTenantNameLength { get; set; } = 64;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
public class EntityChangeConsts
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value: 128
|
||||
/// </summary>
|
||||
public static int MaxEntityTypeFullNameLength { get; set; } = 128;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 128
|
||||
/// </summary>
|
||||
public static int MaxEntityIdLength { get; set; } = 128;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
public class EntityPropertyChangeConsts
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value: 512
|
||||
/// </summary>
|
||||
public static int MaxNewValueLength { get; set; } = 512;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 512
|
||||
/// </summary>
|
||||
public static int MaxOriginalValueLength { get; set; } = 512;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 128
|
||||
/// </summary>
|
||||
public static int MaxPropertyNameLength { get; set; } = 128;
|
||||
|
||||
/// <summary>
|
||||
/// Default value: 64
|
||||
/// </summary>
|
||||
public static int MaxPropertyTypeFullNameLength { get; set; } = 64;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared
|
||||
{
|
||||
public class YiFrameworkAuditLoggingDomainSharedModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
[DisableAuditing]
|
||||
public class AuditLogAggregateRoot: AggregateRoot<Guid>, IMultiTenant
|
||||
{
|
||||
public AuditLogAggregateRoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AuditLogAggregateRoot(
|
||||
Guid id,
|
||||
string applicationName,
|
||||
Guid? tenantId,
|
||||
string tenantName,
|
||||
Guid? userId,
|
||||
string userName,
|
||||
DateTime executionTime,
|
||||
int executionDuration,
|
||||
string clientIpAddress,
|
||||
string clientName,
|
||||
string clientId,
|
||||
string correlationId,
|
||||
string browserInfo,
|
||||
string httpMethod,
|
||||
string url,
|
||||
int? httpStatusCode,
|
||||
Guid? impersonatorUserId,
|
||||
string impersonatorUserName,
|
||||
Guid? impersonatorTenantId,
|
||||
string impersonatorTenantName,
|
||||
ExtraPropertyDictionary extraPropertyDictionary,
|
||||
List<EntityChangeEntity> entityChanges,
|
||||
List<AuditLogActionEntity> actions,
|
||||
string exceptions,
|
||||
string comments)
|
||||
: base(id)
|
||||
{
|
||||
ApplicationName = applicationName.Truncate(AuditLogConsts.MaxApplicationNameLength);
|
||||
TenantId = tenantId;
|
||||
TenantName = tenantName.Truncate(AuditLogConsts.MaxTenantNameLength);
|
||||
UserId = userId;
|
||||
UserName = userName.Truncate(AuditLogConsts.MaxUserNameLength);
|
||||
ExecutionTime = executionTime;
|
||||
ExecutionDuration = executionDuration;
|
||||
ClientIpAddress = clientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength);
|
||||
ClientName = clientName.Truncate(AuditLogConsts.MaxClientNameLength);
|
||||
ClientId = clientId.Truncate(AuditLogConsts.MaxClientIdLength);
|
||||
CorrelationId = correlationId.Truncate(AuditLogConsts.MaxCorrelationIdLength);
|
||||
BrowserInfo = browserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
|
||||
HttpMethod = httpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength);
|
||||
Url = url.Truncate(AuditLogConsts.MaxUrlLength);
|
||||
HttpStatusCode = httpStatusCode;
|
||||
ImpersonatorUserId = impersonatorUserId;
|
||||
ImpersonatorUserName = impersonatorUserName.Truncate(AuditLogConsts.MaxUserNameLength);
|
||||
ImpersonatorTenantId = impersonatorTenantId;
|
||||
ImpersonatorTenantName = impersonatorTenantName.Truncate(AuditLogConsts.MaxTenantNameLength);
|
||||
ExtraProperties = extraPropertyDictionary;
|
||||
EntityChanges = entityChanges;
|
||||
Actions = actions;
|
||||
Exceptions = exceptions;
|
||||
Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength);
|
||||
}
|
||||
|
||||
public virtual string ApplicationName { get; set; }
|
||||
|
||||
public virtual Guid? UserId { get; protected set; }
|
||||
|
||||
public virtual string UserName { get; protected set; }
|
||||
|
||||
public virtual string TenantName { get; protected set; }
|
||||
|
||||
public virtual Guid? ImpersonatorUserId { get; protected set; }
|
||||
|
||||
public virtual string ImpersonatorUserName { get; protected set; }
|
||||
|
||||
public virtual Guid? ImpersonatorTenantId { get; protected set; }
|
||||
|
||||
public virtual string ImpersonatorTenantName { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
|
||||
public virtual string ClientIpAddress { get; protected set; }
|
||||
|
||||
public virtual string ClientName { get; protected set; }
|
||||
|
||||
public virtual string ClientId { get; set; }
|
||||
|
||||
public virtual string CorrelationId { get; set; }
|
||||
|
||||
public virtual string BrowserInfo { get; protected set; }
|
||||
|
||||
public virtual string HttpMethod { get; protected set; }
|
||||
|
||||
public virtual string Url { get; protected set; }
|
||||
|
||||
public virtual string Exceptions { get; protected set; }
|
||||
|
||||
public virtual string Comments { get; protected set; }
|
||||
|
||||
public virtual int? HttpStatusCode { get; set; }
|
||||
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
public virtual List<EntityChangeEntity> EntityChanges { get; protected set; }
|
||||
|
||||
public virtual List<AuditLogActionEntity> Actions { get; protected set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities;
|
||||
|
||||
[DisableAuditing]
|
||||
public class AuditLogActionEntity : Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
|
||||
public virtual Guid AuditLogId { get; protected set; }
|
||||
|
||||
public virtual string ServiceName { get; protected set; }
|
||||
|
||||
public virtual string MethodName { get; protected set; }
|
||||
|
||||
public virtual string Parameters { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
|
||||
|
||||
protected AuditLogActionEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public AuditLogActionEntity(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo, Guid? tenantId = null)
|
||||
{
|
||||
|
||||
Id = id;
|
||||
TenantId = tenantId;
|
||||
AuditLogId = auditLogId;
|
||||
ExecutionTime = actionInfo.ExecutionTime;
|
||||
ExecutionDuration = actionInfo.ExecutionDuration;
|
||||
|
||||
ServiceName = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength);
|
||||
MethodName = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength);
|
||||
Parameters = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
public class EntityChangeEntity : Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public virtual Guid AuditLogId { get; protected set; }
|
||||
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
|
||||
public virtual DateTime ChangeTime { get; protected set; }
|
||||
|
||||
public virtual EntityChangeType ChangeType { get; protected set; }
|
||||
|
||||
public virtual Guid? EntityTenantId { get; protected set; }
|
||||
|
||||
public virtual string EntityId { get; protected set; }
|
||||
|
||||
public virtual string EntityTypeFullName { get; protected set; }
|
||||
|
||||
public virtual ICollection<EntityPropertyChangeEntity> PropertyChanges { get; protected set; }
|
||||
|
||||
|
||||
public EntityChangeEntity(
|
||||
IGuidGenerator guidGenerator,
|
||||
Guid auditLogId,
|
||||
EntityChangeInfo entityChangeInfo,
|
||||
Guid? tenantId = null)
|
||||
{
|
||||
Id = guidGenerator.Create();
|
||||
AuditLogId = auditLogId;
|
||||
TenantId = tenantId;
|
||||
ChangeTime = entityChangeInfo.ChangeTime;
|
||||
ChangeType = entityChangeInfo.ChangeType;
|
||||
EntityTenantId = entityChangeInfo.EntityTenantId;
|
||||
EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength);
|
||||
EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength);
|
||||
|
||||
PropertyChanges = entityChangeInfo
|
||||
.PropertyChanges?
|
||||
.Select(p => new EntityPropertyChangeEntity(guidGenerator, Id, p, tenantId))
|
||||
.ToList()
|
||||
?? new List<EntityPropertyChangeEntity>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
public class EntityPropertyChangeEntity:Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public EntityPropertyChangeEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public EntityPropertyChangeEntity(
|
||||
IGuidGenerator guidGenerator,
|
||||
Guid entityChangeId,
|
||||
EntityPropertyChangeInfo entityChangeInfo,
|
||||
Guid? tenantId = null)
|
||||
{
|
||||
Id = guidGenerator.Create();
|
||||
TenantId = tenantId;
|
||||
EntityChangeId = entityChangeId;
|
||||
NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength);
|
||||
OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength);
|
||||
PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
|
||||
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength);
|
||||
}
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
public virtual Guid EntityChangeId { get; protected set; }
|
||||
|
||||
public virtual string NewValue { get; protected set; }
|
||||
|
||||
public virtual string OriginalValue { get; protected set; }
|
||||
|
||||
public virtual string PropertyName { get; protected set; }
|
||||
|
||||
public virtual string PropertyTypeFullName { get; protected set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Auditing" Version="8.0.0" />
|
||||
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.AuditLogging.Domain.Shared\Yi.Framework.AuditLogging.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain
|
||||
{
|
||||
public class YiFrameworkAuditLoggingDomainModule
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace Yi.Framework.Rbac.SqlSugarCore
|
||||
var roleInfo = CurrentUser.GetRoleInfo();
|
||||
|
||||
//如果无岗位,或者无角色,只能看自己的数据
|
||||
if (CurrentUser.GetDeptId() is null || roleInfo is null)
|
||||
if (/*CurrentUser.GetDeptId() is null ||*/ roleInfo is null)
|
||||
{
|
||||
expUser.Or(it => it.Id == CurrentUser.Id);
|
||||
expRole.Or(it => roleInfo.Select(x=>x.Id).Contains(it.Id));
|
||||
|
||||
Reference in New Issue
Block a user