| | 1 | | using Audit.Core; |
| | 2 | | using Syki.Back.Audit; |
| | 3 | | using Syki.Back.Features.Academic.CreateCampus; |
| | 4 | |
|
| | 5 | | namespace Syki.Back.Configs; |
| | 6 | |
|
| | 7 | | public static class AuditConfigs |
| | 8 | | { |
| | 9 | | public static void AddAuditConfigs(this WebApplicationBuilder _) |
| | 10 | | { |
| 4 | 11 | | Configuration.Setup().UseEntityFramework(_ => _ |
| 2 | 12 | | .AuditTypeExplicitMapper(_ => _ |
| 2 | 13 | | .Map<Campus, AuditLog>() |
| 358 | 14 | | .AuditEntityAction<AuditLog>((evt, entry, log) => log.Fill(evt, entry))) |
| 4 | 15 | | .IgnoreMatchedProperties(true)); |
| 2 | 16 | | } |
| | 17 | |
|
| | 18 | | public static void UseAudit(this IApplicationBuilder app) |
| | 19 | | { |
| 2 | 20 | | var contextAccessor = app.ApplicationServices.GetService<IHttpContextAccessor>()!; |
| | 21 | |
|
| 2 | 22 | | Configuration.AddCustomAction(ActionType.OnScopeCreated, scope => |
| 2 | 23 | | { |
| 15922 | 24 | | var httpContext = contextAccessor.HttpContext; |
| 21286 | 25 | | if (httpContext == null) return; |
| 2 | 26 | |
|
| 10558 | 27 | | if (!httpContext.User.IsAuthenticated) |
| 2 | 28 | | { |
| 3650 | 29 | | scope.Event.CustomFields["Skip"] = true; |
| 3650 | 30 | | return; |
| 2 | 31 | | } |
| 2 | 32 | |
|
| 6908 | 33 | | scope.Event.CustomFields["UserId"] = httpContext.User.Id; |
| 6908 | 34 | | scope.Event.CustomFields["InstitutionId"] = httpContext.User.InstitutionId; |
| 6910 | 35 | | }); |
| 2 | 36 | | } |
| | 37 | | } |