< Summary

Information
Class: Syki.Back.Configs.AuditConfigs
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Configs/AuditConfigs.cs
Tag: 22_11348620282
Line coverage
100%
Covered lines: 35
Uncovered lines: 0
Coverable lines: 35
Total lines: 60
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAuditConfigs(...)100%11100%
UseAudit(...)100%44100%

File(s)

/home/runner/work/syki/syki/Back/Configs/AuditConfigs.cs

#LineLine coverage
 1using Audit.Core;
 2using Syki.Back.Audit;
 3using Syki.Back.Features.Cross.CreateUser;
 4using Syki.Back.Features.Academic.CreateClass;
 5using Syki.Back.Features.Academic.CreateCourse;
 6using Syki.Back.Features.Academic.CreateCampus;
 7using Syki.Back.Features.Academic.CreateTeacher;
 8using Syki.Back.Features.Academic.CreateStudent;
 9using Syki.Back.Features.Cross.CreateInstitution;
 10using Syki.Back.Features.Academic.CreateDiscipline;
 11using Syki.Back.Features.Academic.CreateNotification;
 12using Syki.Back.Features.Academic.CreateCourseOffering;
 13using Syki.Back.Features.Academic.CreateCourseCurriculum;
 14
 15namespace Syki.Back.Configs;
 16
 17public static class AuditConfigs
 18{
 19    public static void AddAuditConfigs(this IServiceCollection _)
 20    {
 221        Configuration.Setup().UseEntityFramework(_ => _
 122            .AuditTypeExplicitMapper(_ => _
 123                .Map<Class, AuditLog>()
 124                .Map<Campus, AuditLog>()
 125                .Map<Course, AuditLog>()
 126                .Map<Schedule, AuditLog>()
 127                .Map<SykiUser, AuditLog>()
 128                .Map<Discipline, AuditLog>()
 129                .Map<SykiStudent, AuditLog>()
 130                .Map<Institution, AuditLog>()
 131                .Map<SykiTeacher, AuditLog>()
 132                .Map<Notification, AuditLog>()
 133                .Map<CourseOffering, AuditLog>()
 134                .Map<CourseCurriculum, AuditLog>()
 135                .Map<CourseDiscipline, AuditLog>()
 136                .Map<CourseCurriculumDiscipline, AuditLog>()
 857937                .AuditEntityAction<AuditLog>((evt, entry, log) => log.Fill(evt, entry)))
 238            .IgnoreMatchedProperties(true));
 139    }
 40
 41    public static void UseAudit(this IApplicationBuilder app)
 42    {
 143        var contextAccessor = app.ApplicationServices.GetService<IHttpContextAccessor>()!;
 44
 145        Configuration.AddCustomAction(ActionType.OnScopeCreated, scope =>
 146        {
 914447            var httpContext = contextAccessor.HttpContext;
 919148            if (httpContext == null) return;
 149
 909750            if (!httpContext.Request.Path.IsAuditable())
 151            {
 134652                scope.Event.CustomFields["Skip"] = true;
 134653                return;
 154            }
 155
 775156            scope.Event.CustomFields["UserId"] = httpContext.User.Id();
 775157            scope.Event.CustomFields["InstitutionId"] = httpContext.User.InstitutionId();
 775258        });
 159    }
 60}