< Summary

Information
Class: Chronicis.Client.Services.AdminAuthService
Assembly: Chronicis.Client
File(s): /home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/AdminAuthService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 18
Coverable lines: 18
Total lines: 38
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
.ctor(...)100%210%
IsSysAdminAsync()0%2040%

File(s)

/home/runner/work/chronicis/chronicis/src/Chronicis.Client/Services/AdminAuthService.cs

#LineLine coverage
 1namespace Chronicis.Client.Services;
 2
 3/// <summary>
 4/// System admin authorization service.
 5/// TODO: Replace hardcoded user check with role-based claims from Auth0.
 6/// </summary>
 7public class AdminAuthService : IAdminAuthService
 8{
 9    private readonly IAuthService _authService;
 10    private readonly ILogger<AdminAuthService> _logger;
 11
 12    // Hardcoded sysadmin identifiers — extend to role-based in the future
 013    private static readonly HashSet<string> SysAdminEmails = new(StringComparer.OrdinalIgnoreCase)
 014    {
 015        "dave@chronicis.app"
 016    };
 17
 018    private static readonly HashSet<string> SysAdminAuth0Ids = new(StringComparer.OrdinalIgnoreCase)
 019    {
 020        "oauth2|discord|992501439685460139"
 021    };
 22
 023    public AdminAuthService(IAuthService authService, ILogger<AdminAuthService> logger)
 24    {
 025        _authService = authService;
 026        _logger = logger;
 027    }
 28
 29    public async Task<bool> IsSysAdminAsync()
 30    {
 031        var user = await _authService.GetCurrentUserAsync();
 032        if (user == null)
 033            return false;
 34
 035        return SysAdminEmails.Contains(user.Email)
 036            || SysAdminAuth0Ids.Contains(user.Auth0UserId);
 037    }
 38}