Browse Source

Skip disabled complex properties in auditing

pull/24767/head
maliming 1 week ago
parent
commit
85770416c6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 6
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 71
      framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs

6
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -510,6 +510,12 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
{
foreach (var complexPropertyEntry in complexPropertyEntries)
{
var complexPropertyInfo = complexPropertyEntry.Metadata.PropertyInfo;
if (complexPropertyInfo != null && complexPropertyInfo.IsDefined(typeof(DisableAuditingAttribute), true))
{
continue;
}
foreach (var propertyEntry in complexPropertyEntry.Properties)
{
yield return propertyEntry;

71
framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using NSubstitute;
using Shouldly;
using Volo.Abp.Auditing.App.Entities;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
@ -911,6 +912,76 @@ public class Auditing_Tests : AbpAuditingTestBase
AuditingStore.ClearReceivedCalls();
#pragma warning restore 4014
}
[Fact]
public async Task Should_Not_Update_Modification_Audit_Properties_When_Only_Disabled_Complex_Property_Changes()
{
var entityId = Guid.NewGuid();
var repository = ServiceProvider.GetRequiredService<IBasicRepository<AppEntityWithComplexProperty, Guid>>();
using (var uow = _unitOfWorkManager.Begin())
{
var entity = new AppEntityWithComplexProperty(entityId, "Test Entity")
{
ContactInformation = new AppEntityContactInformation
{
Street = "First Street",
Location = new AppEntityContactLocation
{
City = "First City"
}
},
DisabledContactInformation = new AppEntityContactInformation
{
Street = "Disabled Street",
Location = new AppEntityContactLocation
{
City = "Disabled City"
}
}
};
await repository.InsertAsync(entity);
await uow.CompleteAsync();
}
using (var uow = _unitOfWorkManager.Begin())
{
var entity = await repository.GetAsync(entityId);
entity.Name = "Updated Test Entity";
await repository.UpdateAsync(entity);
await uow.CompleteAsync();
}
DateTime? lastModificationTime;
using (var uow = _unitOfWorkManager.Begin())
{
var entity = await repository.GetAsync(entityId);
lastModificationTime = entity.LastModificationTime;
lastModificationTime.ShouldNotBeNull();
await uow.CompleteAsync();
}
await Task.Delay(10);
using (var uow = _unitOfWorkManager.Begin())
{
var entity = await repository.GetAsync(entityId);
entity.DisabledContactInformation.Street = "Updated Disabled Street";
await repository.UpdateAsync(entity);
await uow.CompleteAsync();
}
using (var uow = _unitOfWorkManager.Begin())
{
var entity = await repository.GetAsync(entityId);
entity.LastModificationTime.ShouldBe(lastModificationTime);
await uow.CompleteAsync();
}
}
}
public class Auditing_DisableLogActionInfo_Tests : Auditing_Tests

Loading…
Cancel
Save