< Summary

Information
Class: Syki.Back.Extensions.UserExtensions
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Extensions/UserExtensions.cs
Tag: 22_11348620282
Line coverage
91%
Covered lines: 21
Uncovered lines: 2
Coverable lines: 23
Total lines: 50
Line coverage: 91.3%
Branch coverage
69%
Covered branches: 16
Total branches: 23
Branch coverage: 69.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
InstitutionId(...)100%11100%
Id(...)100%11100%
GetCourseCurriculumId(...)100%11100%
IsOnlyInRole()46.15%13.621384.61%
IsAuditable(...)100%1010100%

File(s)

/home/runner/work/syki/syki/Back/Extensions/UserExtensions.cs

#LineLine coverage
 1using System.Security.Claims;
 2using Syki.Back.Features.Cross.CreateUser;
 3
 4namespace Syki.Back.Extensions;
 5
 6public static class UserExtensions
 7{
 8    public static Guid InstitutionId(this ClaimsPrincipal user)
 9    {
 1138910        return Guid.Parse(user.FindFirstValue("institution")!);
 11    }
 12
 13    public static Guid Id(this ClaimsPrincipal user)
 14    {
 801215        return Guid.Parse(user.FindFirstValue("sub")!);
 16    }
 17
 18    public static Guid GetCourseCurriculumId(this ClaimsPrincipal user)
 19    {
 5120        return Guid.Parse(user.FindFirstValue("CourseCurriculumId")!);
 21    }
 22
 23    public static async Task<bool> IsOnlyInRole(this UserManager<SykiUser> userManager, SykiUser user, UserRole role)
 24    {
 425        var adm = await userManager.IsInRoleAsync(user!, UserRole.Adm.ToString());
 426        var student = await userManager.IsInRoleAsync(user!, UserRole.Student.ToString());
 427        var teacher = await userManager.IsInRoleAsync(user!, UserRole.Teacher.ToString());
 428        var academic = await userManager.IsInRoleAsync(user!, UserRole.Academic.ToString());
 29
 430        return role switch
 431        {
 232            UserRole.Academic => academic && !(adm || student || teacher),
 133            UserRole.Student => student && !(adm || academic || teacher),
 134            UserRole.Teacher => teacher && !(adm || student || academic),
 035            UserRole.Adm => adm && !(student || teacher || academic),
 036            _ => false
 437        };
 438    }
 39
 40    public static bool IsAuditable(this PathString path)
 41    {
 910442        return
 910443            path != "/login" &&
 910444            path != "/skip-user-register" &&
 910445            path != "/login/mfa" &&
 910446            path != "/reset-password" &&
 910447            path != "/users" &&
 910448            path != "/reset-password-token";
 49    }
 50}