< Summary

Information
Class: Elsa.Identity.Endpoints.Permissions.Reach.Response
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Permissions/Reach/Endpoint.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 53
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Resource()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Permissions/Reach/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Authorization;
 3using Elsa.Identity.Permissions;
 4using Elsa.Permissions;
 5using FastEndpoints;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Identity.Endpoints.Permissions.Reach;
 9
 10/// <summary>What a wildcard grant covers right now.</summary>
 11/// <param name="Covers">
 12/// A point-in-time snapshot. A wildcard grant also covers resources registered later, so a role editor
 13/// should present this as "currently covers", not as a fixed list.
 14/// </param>
 015public record Response(string Resource, IReadOnlyCollection<string> Covers, int Count);
 16
 17/// <summary>The resource pattern to report on, for example <c>workflows/*</c>.</summary>
 18public class Request
 19{
 20    /// <summary>The resource pattern.</summary>
 21    public string Resource { get; set; } = null!;
 22}
 23
 24/// <summary>
 25/// Reports the resources a grant currently covers. This is the mitigation for forward reach on the
 26/// resource axis: a wildcard is convenient precisely because it covers things that do not exist yet,
 27/// so an author needs a way to see what it reaches today.
 28/// </summary>
 29[PublicAPI]
 30internal class Reach(IPermissionDescriptorRegistry registry) : ElsaEndpoint<Request, Response>
 31{
 32    /// <inheritdoc />
 33    public override void Configure()
 34    {
 35        Get("/identity/permissions/reach");
 36        RequirePermission(IdentityPermissions.Roles, CoreVerbs.View);
 37    }
 38
 39    /// <inheritdoc />
 40    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 41    {
 42        if (string.IsNullOrWhiteSpace(request.Resource))
 43        {
 44            AddError(nameof(request.Resource), "A resource pattern is required.");
 45            await Send.ErrorsAsync(cancellation: cancellationToken);
 46            return;
 47        }
 48
 49        var covers = registry.Reach(request.Resource.Trim());
 50
 51        await Send.OkAsync(new Response(request.Resource.Trim(), covers, covers.Count), cancellationToken);
 52    }
 53}

Methods/Properties

get_Resource()