< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.Scripting.ExpressionDescriptors.List.ExpressionDescriptorModel
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
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 63
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_Type()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]
 15internal 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>
 28    private static readonly FrozenSet<string> HostCodeExpressionTypes = new[] { "CSharp", "Python" }.ToFrozenSet(StringC
 29
 30    /// <inheritdoc />
 31    public override void Configure()
 32    {
 33        Get("/descriptors/expression-descriptors");
 34        RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.DescriptorsExpressions, CoreVerbs.View);
 35    }
 36
 37    /// <inheritdoc />
 38    public override Task HandleAsync(CancellationToken cancellationToken)
 39    {
 40        var descriptors = expressionDescriptorRegistry.ListAll().Where(CanListDescriptor).ToList();
 41        var models = Map(descriptors).ToList();
 42        var response = new ListResponse<ExpressionDescriptorModel>(models);
 43        return Send.OkAsync(response, cancellationToken);
 44    }
 45
 46    private static bool CanListDescriptor(ExpressionDescriptor descriptor) =>
 47        !HostCodeExpressionTypes.Contains(descriptor.Type) || descriptor.IsBrowsable;
 48
 49    private static IEnumerable<ExpressionDescriptorModel> Map(List<ExpressionDescriptor> descriptors) => descriptors.Sel
 50
 51    private static ExpressionDescriptorModel Map(ExpressionDescriptor descriptor)
 52    {
 53        var properties = descriptor.Properties;
 54        return new ExpressionDescriptorModel(
 55            descriptor.Type,
 56            descriptor.DisplayName,
 57            descriptor.IsSerializable,
 58            descriptor.IsBrowsable,
 59            properties);
 60    }
 61}
 62
 063internal record ExpressionDescriptorModel(string Type, string DisplayName, bool IsSerializable, bool IsBrowsable, IDicti

Methods/Properties

get_Type()