< Summary

Information
Class: Elsa.ExternalAuthentication.Permissions.ElsaRolePermissionGrantSource
Assembly: Elsa.ExternalAuthentication
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Permissions/ElsaRolePermissionGrantSource.cs
Line coverage
87%
Covered lines: 14
Uncovered lines: 2
Coverable lines: 16
Total lines: 31
Line coverage: 87.5%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Type()100%11100%
Describe()100%210%
GetGrantsAsync()50%4490%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.ExternalAuthentication/Permissions/ElsaRolePermissionGrantSource.cs

#LineLine coverage
 1using Elsa.ExternalAuthentication.Contracts;
 2using Elsa.ExternalAuthentication.Models;
 3using Elsa.Identity.Contracts;
 4using Elsa.Identity.Models;
 5
 6namespace Elsa.ExternalAuthentication.Permissions;
 7
 188public sealed class ElsaRolePermissionGrantSource(IUserProvider userProvider, IRoleProvider roleProvider) : IPermissionG
 9{
 10    public const string SourceType = "elsa-roles";
 2211    public string Type => SourceType;
 12
 013    public PermissionGrantSourceDescriptor Describe() => new(Type, "Elsa roles", "Grants the permissions assigned to the
 14
 15    public async ValueTask<PermissionGrantResult> GetGrantsAsync(PermissionGrantContext context, CancellationToken cance
 16    {
 217        var user = await userProvider.FindAsync(new()
 218            { Id = context.UserId }, cancellationToken);
 219        if (user is null || !string.Equals(user.TenantId, context.TargetTenantId, StringComparison.Ordinal))
 020            return new([], [new("user_not_available", "The Elsa user is not available in the target tenant.")]);
 21
 222        var roles = await roleProvider.FindManyAsync(new()
 223            { Ids = user.Roles.ToArray() }, cancellationToken);
 224        var grants = roles
 225            .Where(x => string.Equals(x.TenantId, context.TargetTenantId, StringComparison.Ordinal))
 226            .OrderBy(x => x.Id, StringComparer.Ordinal)
 1427            .SelectMany(role => role.Permissions.Where(permission => !string.IsNullOrWhiteSpace(permission)).OrderBy(per
 228            .ToArray();
 229        return new(grants, []);
 230    }
 31}