Açık Kapalı

Audit Logging Issue for Entities with nested objects #7165


User avatar
0
gilina.mcbride oluşturuldu
  • ABP Framework version: v7.3.0
  • UI Type: MVC
  • Database System: EF Core (SQL Server)
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes/no
  • Problem:

We have a few entities that have nested objects. For example Processing Configuration entity has Payment settings object: public PaymentSettings PaymentSettings { get; set; } = new PaymentSettings(); However these are not separate tables in the database. The properties are on the processing configuration table as processingConfiguration.paymentSettings.FieldName. The issue we're having is that when we do audit logging for the entity, if we change a property that is in a nested object it isn't logging properly (see screenshot). It sees there is a change/update, but not what property has been changed or any other information. Is there a work around for this issue?


10 Cevap
  • User Avatar
    0
    liangshiwei oluşturuldu
    Destek Takımı Fullstack Developer

    Hi,

    Could you share a simple project to reproduce the problem? thanks. my email is shiwei.liang@volosoft.com

  • User Avatar
    0
    gilina.mcbride oluşturuldu

    I just sent you an example to your email. Thank you!

  • User Avatar
    0
    liangshiwei oluşturuldu
    Destek Takımı Fullstack Developer

    Hi,

    Sorry, but the file was blocked from downloading.

  • User Avatar
    0
    gilina.mcbride oluşturuldu

    Ok I sent a shared link, hopefully you can open that one. Thanks!

  • User Avatar
    0
    liangshiwei oluşturuldu
    Destek Takımı Fullstack Developer

    I spent a long time downloading the file but with no success.

    Could you try share the file with https://wetransfer.com/

  • User Avatar
    0
    gilina.mcbride oluşturuldu

    I've emailed a few things in the hopes one of them works. I have also attached two screenshots of how we've structured our dtos that are causing the issue, and a gif so you can see that when I create or edit a contact that includes the nested dto the nested items aren't included in the audit log, the only change that shows is the one made to email which is on the contactdto not the paymentsettingsdto. The others aren't included in the log which is the issue were trying to solve for.

    Dtos:

    gif:

  • User Avatar
    0
    liangshiwei oluşturuldu
    Destek Takımı Fullstack Developer

    I received the email, but it only contains .sln file

  • User Avatar
    0
    gilina.mcbride oluşturuldu

    I sent a zipped folder through wetransfer. It wouldn't upload a non zipped one. Hopefully you'll be able to open. I have also included information two comments above if that would help any.

  • User Avatar
    0
    liangshiwei oluşturuldu
    Destek Takımı Fullstack Developer

    Hi

    ABP is not supported in this case, you can try overriding the EntityHistoryHelper:

    [Dependency(ReplaceServices = true)]
    public class CustomEntityHistoryHelper : EntityHistoryHelper
    {
    
        public CustomEntityHistoryHelper(IAuditingStore auditingStore, IOptions<AbpAuditingOptions> options, IClock clock, IJsonSerializer jsonSerializer, IAuditingHelper auditingHelper) : base(auditingStore, options, clock, jsonSerializer, auditingHelper)
        {
        }
        
        
        protected override List<EntityPropertyChangeInfo> GetPropertyChanges(EntityEntry entityEntry)
        {
            var propertyChanges = base.GetPropertyChanges(entityEntry);
    
            foreach (ReferenceEntry reference in entityEntry.References)
            {
                if (reference.TargetEntry == null)
                {
                    continue;
                }
    
                var referencePropertyChanges = GetPropertyChanges(reference.TargetEntry);
    
                foreach (EntityPropertyChangeInfo referencePropertyChange in referencePropertyChanges)
                {
                    referencePropertyChange.PropertyName = $"{reference.Metadata.Name}.{referencePropertyChange.PropertyName}";
                }
    
                propertyChanges.AddRange(referencePropertyChanges);
            }
    
            return propertyChanges;
        }
    }
    
  • User Avatar
    0
    gilina.mcbride oluşturuldu

    This work around solved the issue. Thank you!

Made with ❤️ on ABP v8.2.0-preview Updated on Mart 25, 2024, 15:11