abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.31k stars 3.32k forks source link

Entity history is not always recorded #11682

Open irvingHerrera opened 2 years ago

irvingHerrera commented 2 years ago

Hi! I am using the history of entities, the project currently started in version 4.3, migrated to 4.4 and finally to version 5.1.3

When the project updated to version 5.1.3 the entity history started to fail. After doing some tests I have been able to notice the following.

The next HubFilter on this line there is nothing UI action (auditingManager.Current.Log.Actions).

Continuing with the tests that I have carried out, I have noticed that it is possibly a concurrency problem when generating the scope of auditingManager and registering the action in the AuditingInterceptor.cs class.

Unfortunately I couldn't solve the problem. Any idea how I could fix this?.

Thank you very much

maliming commented 2 years ago

hi

You can replace it with your AuditHubFilter. I will check the Actions issue.

https://github.com/abpframework/abp/blob/e3e1779de6df5d26f01cdc8e99ac9cbcb3d24d3c/framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs#L42

irvingHerrera commented 2 years ago

I have replaced AuditHubFilter with a custom one but I still can't find the problem. I managed to see that every UI related action generates a scope for audilog.

I have verified that it is possible to filter with auditingManager.Current.Log.Actions.IsNullOrEmpty(). But I have noticed that the actions are generated when some method of the Applications layer is called. Then AuditingInterceptor comes into action but I have not been able to verify what the interceptor comes from on which generated scope.

A scope is generated for each event performed on the UI (click, hover, over, mousevent, etc.)

I have been able to notice that if it detects the changes made in the entity but there comes a point where the tracking of the action is lost is there a way in AuditingIntercept to know which scope corresponds to the generated action?

Thank you very much

maliming commented 2 years ago

hi

I made a new changes: https://github.com/abpframework/abp/pull/11687

irvingHerrera commented 2 years ago

Hi maliming.

I hope you are well. I have updated abp to version 5.1.4 where I can see your changes being applied. But the above mentioned problem here persists

I was able to detect that in the AuditingInterceptor class on the line he execution of the method is done in the application layer, which is just when I perform an action on the database

In the AbpDbContext class on this line auditLog is null and does not get the changes made to the entity.

Apparently the scope that arrives in SaveChangesAsync is not the same as the one that is being executed in AuditingInterceptor but auditLog is initialized in the AuditingInterceptor class.

I've been trying to figure this out but couldn't find a solution, do you have any idea how I could solve this? Thank you very much

I have prepared an example repository where you can see the behavior mentioned here repo

maliming commented 2 years ago

hi

I will check it.

maliming commented 2 years ago

See https://github.com/abpframework/abp/pull/11807

context.Services.AddSignalR(options =>
{
    var p = options.GetType().GetProperty("HubFilters", BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic);
    var pp = p.GetValue(options);
    var m = typeof(List<IHubFilter>).GetMethod("Clear");
    m.Invoke(pp, BindingFlags.Default, null, null, null);

    options.AddFilter<AbpHubContextAccessorHubFilter>();
    options.AddFilter<AbpAuthenticationHubFilter>();
    options.AddFilter<AbpUowHubFilter>();
    options.AddFilter<AbpAuditHubFilter>();
});
irvingHerrera commented 2 years ago

Hi maliming.

i have checked the latest version of abp 5.2 RC1 I can notice that the changes mentioned here are already implemented. But now I see that they have removed the AbpAuditHubFilter filter.

I've made the changes you mention to the signalr middleware and it overrides the AbpUowHubFilter filter so it doesn't do anything so entity history is back to work

Will anything change for the final 5.2 release as an internal fix for abp?

Thank you

maliming commented 2 years ago

Since Blazor's mechanism(https://github.com/dotnet/aspnetcore/issues/30115) AbpUowHubFiltermay be have bugs, I rolled back the commit and am working on the latest solution.

magicjar commented 1 year ago

Any news on this?

maliming commented 1 year ago

No. https://github.com/abpframework/abp/issues/11682#issuecomment-1066064249

puschie286 commented 1 year ago

It looks like Microsoft won't be fixing the problem anytime soon what do you recommend as a workaround - audit logging is a security feature, so the current state is a security risk Currently, only deletions are logged

Is it possible to trigger the audit logging manually ( within dbcontext or the repository ) ?

alpisala02 commented 1 year ago

Is there any solutions ? Its been more than a year since this ticket opened. We need help.

maliming commented 1 year ago

No. https://github.com/abpframework/abp/issues/11682#issuecomment-1066064249

ogulcancakir commented 1 year ago

It looks like Microsoft won't be fixing the problem anytime soon what do you recommend as a workaround - audit logging is a security feature, so the current state is a security risk Currently, only deletions are logged

Is it possible to trigger the audit logging manually ( within dbcontext or the repository ) ?

@puschie286 Have you found a solution in this way?

puschie286 commented 1 year ago

@ogulcancakir sry but no - only not to rely on the entity history :/

alireza-4taghavi commented 11 months ago

Is this fixed now guys?

maliming commented 11 months ago

Not yet.

Is this fixed now guys?

alireza-4taghavi commented 11 months ago

Is there any work around on this? I really need to have the entity changes to my system, we are going to publish our product soon

alireza-4taghavi commented 11 months ago

Only one or two entity to have their logs in enough for now

maliming commented 11 months ago

https://github.com/abpframework/abp/issues/11682#issuecomment-1066064249

alireza-4taghavi commented 11 months ago

Can you guide me more please? how to solve it ?

maliming commented 11 months ago

Due to the current limitations of blazor, it cannot be resolved.

alireza-4taghavi commented 11 months ago

So any alternative way to implement this feature?

margareteryan commented 11 months ago

I am also in need of an alternative. Audit log is necessary for our site.

MannRobertJ commented 6 months ago

See #11807

context.Services.AddSignalR(options =>
{
    var p = options.GetType().GetProperty("HubFilters", BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic);
    var pp = p.GetValue(options);
    var m = typeof(List<IHubFilter>).GetMethod("Clear");
    m.Invoke(pp, BindingFlags.Default, null, null, null);

    options.AddFilter<AbpHubContextAccessorHubFilter>();
    options.AddFilter<AbpAuthenticationHubFilter>();
    options.AddFilter<AbpUowHubFilter>();
    options.AddFilter<AbpAuditHubFilter>();
});

This solution without AbpUowHubFiler and AbpAuditHubFilter seems to work. Is this currently a recommended approach?

maliming commented 6 months ago

hi @MannRobertJ

There are currently no other options.

Jawad-Chughtai commented 1 month ago

Hi, I am also facing the same issue. Did it get resolved in .Net 8 ?

maliming commented 1 month ago

Hi, I am also facing the same issue. Did it get resolved in .Net 8 ?

Not yet.

liuahifancy commented 3 weeks ago

Abp 8.1.1 also not fixed,Follow-up continue to follow