< Summary

Information
Class: Elsa.Identity.Multitenancy.CurrentUserTenantResolver
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Multitenancy/CurrentUserTenantResolver.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 36
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
ResolveAsync()0%7280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Multitenancy/CurrentUserTenantResolver.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Identity.Contracts;
 3using Elsa.Identity.Models;
 4using Microsoft.AspNetCore.Http;
 5
 6namespace Elsa.Identity.Multitenancy;
 7
 8/// <summary>
 9/// Resolves the tenant from the current user.
 10/// </summary>
 011public class CurrentUserTenantResolver(IUserProvider userProvider, IHttpContextAccessor httpContextAccessor) : TenantRes
 12{
 13    /// <inheritdoc />
 14    protected override async Task<TenantResolverResult> ResolveAsync(TenantResolverContext context)
 15    {
 016        var httpContext = httpContextAccessor.HttpContext;
 17
 018        if (httpContext == null)
 019            return Unresolved();
 20
 021        var userName = httpContext.User.Identity?.Name;
 22
 023        if (userName == null)
 024            return Unresolved();
 25
 026        var cancellationToken = context.CancellationToken;
 027        var filter = new UserFilter
 028        {
 029            Name = userName
 030        };
 031        var user = await userProvider.FindAsync(filter, cancellationToken);
 032        var tenantId = user?.TenantId;
 33
 034        return AutoResolve(tenantId);
 035    }
 36}