| | 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>() |
| 296 | 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 | | { |
| 14748 | 24 | | var httpContext = contextAccessor.HttpContext; |
| 19822 | 25 | | if (httpContext == null) return; |
| 2 | 26 | |
|
| 9674 | 27 | | if (!httpContext.User.IsAuthenticated) |
| 2 | 28 | | { |
| 3394 | 29 | | scope.Event.CustomFields["Skip"] = true; |
| 3394 | 30 | | return; |
| 2 | 31 | | } |
| 2 | 32 | |
|
| 6280 | 33 | | scope.Event.CustomFields["UserId"] = httpContext.User.Id; |
| 6280 | 34 | | scope.Event.CustomFields["InstitutionId"] = httpContext.User.InstitutionId; |
| 6282 | 35 | | }); |
| 2 | 36 | | } |
| | 37 | | } |