| | 1 | | using Audit.Core; |
| | 2 | | using Syki.Back.Audit; |
| | 3 | | using Syki.Back.Features.Cross.CreateUser; |
| | 4 | | using Syki.Back.Features.Academic.CreateClass; |
| | 5 | | using Syki.Back.Features.Academic.CreateCourse; |
| | 6 | | using Syki.Back.Features.Academic.CreateCampus; |
| | 7 | | using Syki.Back.Features.Academic.CreateTeacher; |
| | 8 | | using Syki.Back.Features.Academic.CreateStudent; |
| | 9 | | using Syki.Back.Features.Cross.CreateInstitution; |
| | 10 | | using Syki.Back.Features.Academic.CreateDiscipline; |
| | 11 | | using Syki.Back.Features.Academic.CreateNotification; |
| | 12 | | using Syki.Back.Features.Academic.CreateCourseOffering; |
| | 13 | | using Syki.Back.Features.Academic.CreateCourseCurriculum; |
| | 14 | |
|
| | 15 | | namespace Syki.Back.Configs; |
| | 16 | |
|
| | 17 | | public static class AuditConfigs |
| | 18 | | { |
| | 19 | | public static void AddAuditConfigs(this IServiceCollection _) |
| | 20 | | { |
| 2 | 21 | | Configuration.Setup().UseEntityFramework(_ => _ |
| 1 | 22 | | .AuditTypeExplicitMapper(_ => _ |
| 1 | 23 | | .Map<Class, AuditLog>() |
| 1 | 24 | | .Map<Campus, AuditLog>() |
| 1 | 25 | | .Map<Course, AuditLog>() |
| 1 | 26 | | .Map<Schedule, AuditLog>() |
| 1 | 27 | | .Map<SykiUser, AuditLog>() |
| 1 | 28 | | .Map<Discipline, AuditLog>() |
| 1 | 29 | | .Map<SykiStudent, AuditLog>() |
| 1 | 30 | | .Map<Institution, AuditLog>() |
| 1 | 31 | | .Map<SykiTeacher, AuditLog>() |
| 1 | 32 | | .Map<Notification, AuditLog>() |
| 1 | 33 | | .Map<CourseOffering, AuditLog>() |
| 1 | 34 | | .Map<CourseCurriculum, AuditLog>() |
| 1 | 35 | | .Map<CourseDiscipline, AuditLog>() |
| 1 | 36 | | .Map<CourseCurriculumDiscipline, AuditLog>() |
| 8579 | 37 | | .AuditEntityAction<AuditLog>((evt, entry, log) => log.Fill(evt, entry))) |
| 2 | 38 | | .IgnoreMatchedProperties(true)); |
| 1 | 39 | | } |
| | 40 | |
|
| | 41 | | public static void UseAudit(this IApplicationBuilder app) |
| | 42 | | { |
| 1 | 43 | | var contextAccessor = app.ApplicationServices.GetService<IHttpContextAccessor>()!; |
| | 44 | |
|
| 1 | 45 | | Configuration.AddCustomAction(ActionType.OnScopeCreated, scope => |
| 1 | 46 | | { |
| 9144 | 47 | | var httpContext = contextAccessor.HttpContext; |
| 9191 | 48 | | if (httpContext == null) return; |
| 1 | 49 | |
|
| 9097 | 50 | | if (!httpContext.Request.Path.IsAuditable()) |
| 1 | 51 | | { |
| 1346 | 52 | | scope.Event.CustomFields["Skip"] = true; |
| 1346 | 53 | | return; |
| 1 | 54 | | } |
| 1 | 55 | |
|
| 7751 | 56 | | scope.Event.CustomFields["UserId"] = httpContext.User.Id(); |
| 7751 | 57 | | scope.Event.CustomFields["InstitutionId"] = httpContext.User.InstitutionId(); |
| 7752 | 58 | | }); |
| 1 | 59 | | } |
| | 60 | | } |