< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Scripting.ExpressionDescriptors.List.List
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Scripting/ExpressionDescriptors/List/Endpoint.cs
Line coverage
22%
Covered lines: 4
Uncovered lines: 14
Coverable lines: 18
Total lines: 63
Line coverage: 22.2%
Branch coverage
0%
Covered branches: 0
Total branches: 2
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%11100%
.cctor()100%210%
Configure()100%11100%
HandleAsync(...)100%210%
CanListDescriptor(...)0%620%
Map(...)100%210%
Map(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/Scripting/ExpressionDescriptors/List/Endpoint.cs

#LineLine coverage
 1using Elsa.Authorization;
 2using System.Collections.Frozen;
 3using Elsa.Abstractions;
 4using Elsa.Expressions.Contracts;
 5using Elsa.Expressions.Models;
 6using Elsa.Models;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Workflows.Api.Endpoints.Scripting.ExpressionDescriptors.List;
 10
 11/// <summary>
 12/// Returns a TypeScript definition that is used by the Monaco editor to display intellisense for JavaScript expressions
 13/// </summary>
 14[UsedImplicitly]
 315internal class List(IExpressionDescriptorRegistry expressionDescriptorRegistry) : ElsaEndpointWithoutRequest<ListRespons
 16{
 17    /// <summary>
 18    /// The expression types the host can switch off, which are omitted entirely rather than listed as
 19    /// non-browsable so a disabled language does not appear in the editor at all. Every other type is listed
 20    /// and carries <c>IsBrowsable</c> for the client to act on.
 21    /// </summary>
 22    /// <remarks>
 23    /// This was a map from expression type to a per-author permission. The permission was only ever read to
 24    /// test membership -- the value went unused even before it was retired -- and the decision has always
 25    /// been the host switch, surfaced as <c>IsBrowsable</c>. A set says that without implying a check that
 26    /// does not happen. Per-author script trust was considered and declined in #7975: the host switch is the control.
 27    /// </remarks>
 028    private static readonly FrozenSet<string> HostCodeExpressionTypes = new[] { "CSharp", "Python" }.ToFrozenSet(StringC
 29
 30    /// <inheritdoc />
 31    public override void Configure()
 32    {
 333        Get("/descriptors/expression-descriptors");
 334        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.DescriptorsExpressions, CoreVerbs.View);
 335    }
 36
 37    /// <inheritdoc />
 38    public override Task HandleAsync(CancellationToken cancellationToken)
 39    {
 040        var descriptors = expressionDescriptorRegistry.ListAll().Where(CanListDescriptor).ToList();
 041        var models = Map(descriptors).ToList();
 042        var response = new ListResponse<ExpressionDescriptorModel>(models);
 043        return Send.OkAsync(response, cancellationToken);
 44    }
 45
 46    private static bool CanListDescriptor(ExpressionDescriptor descriptor) =>
 047        !HostCodeExpressionTypes.Contains(descriptor.Type) || descriptor.IsBrowsable;
 48
 049    private static IEnumerable<ExpressionDescriptorModel> Map(List<ExpressionDescriptor> descriptors) => descriptors.Sel
 50
 51    private static ExpressionDescriptorModel Map(ExpressionDescriptor descriptor)
 52    {
 053        var properties = descriptor.Properties;
 054        return new ExpressionDescriptorModel(
 055            descriptor.Type,
 056            descriptor.DisplayName,
 057            descriptor.IsSerializable,
 058            descriptor.IsBrowsable,
 059            properties);
 60    }
 61}
 62
 63internal record ExpressionDescriptorModel(string Type, string DisplayName, bool IsSerializable, bool IsBrowsable, IDicti