< 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
85%
Covered lines: 12
Uncovered lines: 2
Coverable lines: 14
Total lines: 29
Line coverage: 85.7%
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%4487.5%

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
 58public sealed class ElsaRolePermissionGrantSource(IUserProvider userProvider, IRoleProvider roleProvider) : IPermissionG
 9{
 10    public const string SourceType = "elsa-roles";
 711    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    {
 117        var user = await userProvider.FindAsync(new UserFilter { Id = context.UserId }, cancellationToken);
 118        if (user is null || !string.Equals(user.TenantId, context.TargetTenantId, StringComparison.Ordinal))
 019            return new PermissionGrantResult([], [new PermissionGrantWarning("user_not_available", "The Elsa user is not
 20
 121        var roles = await roleProvider.FindManyAsync(new RoleFilter { Ids = user.Roles.ToArray() }, cancellationToken);
 122        var grants = roles
 123            .Where(x => string.Equals(x.TenantId, context.TargetTenantId, StringComparison.Ordinal))
 124            .OrderBy(x => x.Id, StringComparer.Ordinal)
 725            .SelectMany(role => role.Permissions.Where(permission => !string.IsNullOrWhiteSpace(permission)).OrderBy(per
 126            .ToArray();
 127        return new PermissionGrantResult(grants, []);
 128    }
 29}