< Summary

Information
Class: Elsa.Identity.Endpoints.Me.Permissions.Get
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Me/Permissions/Endpoint.cs
Line coverage
40%
Covered lines: 4
Uncovered lines: 6
Coverable lines: 10
Total lines: 39
Line coverage: 40%
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
.ctor(...)100%11100%
Configure()100%11100%
ExecuteAsync(...)100%210%

File(s)

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

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Authorization;
 3using Elsa.Permissions;
 4using JetBrains.Annotations;
 5
 6namespace Elsa.Identity.Endpoints.Me.Permissions;
 7
 8/// <summary>
 9/// Returns the calling principal's effective grants, so a client can hide sections, disable actions and
 10/// show read-only states from one call rather than probing endpoints.
 11/// </summary>
 12/// <remarks>
 13/// This is for rendering. The source of truth is always server-side: every protected endpoint
 14/// re-evaluates independently, and this response is never an authorization decision.
 15/// </remarks>
 16[PublicAPI]
 317internal class Get(IPermissionDescriptorRegistry registry, IPermissionEvaluator evaluator) : ElsaEndpointWithoutRequest<
 18{
 19    /// <inheritdoc />
 20    public override void Configure()
 21    {
 322        Get("/identity/me/permissions");
 23
 24        // Any authenticated principal may ask what it holds; no grant is required to see your own.
 325        RequireAuthenticatedOnly();
 326    }
 27
 28    /// <inheritdoc />
 29    public override Task<Response> ExecuteAsync(CancellationToken cancellationToken)
 30    {
 031        var grants = registry.List()
 032            .Select(descriptor => new ResourceGrant(
 033                descriptor.Resource,
 034                descriptor.SupportedVerbs.Where(verb => evaluator.HasPermission(User, descriptor.Resource, verb)).ToArra
 035            .ToArray();
 36
 037        return Task.FromResult(new Response(grants));
 38    }
 39}