< 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: 60
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 System.Collections.Frozen;
 2using Elsa.Abstractions;
 3using Elsa.Expressions.Contracts;
 4using Elsa.Expressions.Models;
 5using Elsa.Models;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Workflows.Api.Endpoints.Scripting.ExpressionDescriptors.List;
 9
 10/// <summary>
 11/// Returns a TypeScript definition that is used by the Monaco editor to display intellisense for JavaScript expressions
 12/// </summary>
 13[UsedImplicitly]
 14internal class List(IExpressionDescriptorRegistry expressionDescriptorRegistry) : ElsaEndpointWithoutRequest<ListRespons
 15{
 16    private static readonly IReadOnlyDictionary<string, string> PrivilegedExpressionPermissions = new Dictionary<string,
 17    {
 18        ["CSharp"] = PermissionNames.ExecuteCSharpExpressions,
 19        ["Python"] = PermissionNames.ExecutePythonExpressions
 20    }.ToFrozenDictionary(StringComparer.Ordinal);
 21
 22    /// <inheritdoc />
 23    public override void Configure()
 24    {
 25        Get("/descriptors/expression-descriptors");
 26        ConfigurePermissions("read:*", "read:expression-descriptors");
 27    }
 28
 29    /// <inheritdoc />
 30    public override Task HandleAsync(CancellationToken cancellationToken)
 31    {
 32        var descriptors = expressionDescriptorRegistry.ListAll().Where(CanListDescriptor).ToList();
 33        var models = Map(descriptors).ToList();
 34        var response = new ListResponse<ExpressionDescriptorModel>(models);
 35        return Send.OkAsync(response, cancellationToken);
 36    }
 37
 38    private bool CanListDescriptor(ExpressionDescriptor descriptor)
 39    {
 40        if (!PrivilegedExpressionPermissions.TryGetValue(descriptor.Type, out var permission))
 41            return true;
 42
 43        return descriptor.IsBrowsable && User.Claims.Any(x => x.Type == PermissionNames.ClaimType && (x.Value == Permiss
 44    }
 45
 46    private static IEnumerable<ExpressionDescriptorModel> Map(List<ExpressionDescriptor> descriptors) => descriptors.Sel
 47
 48    private static ExpressionDescriptorModel Map(ExpressionDescriptor descriptor)
 49    {
 50        var properties = descriptor.Properties;
 51        return new ExpressionDescriptorModel(
 52            descriptor.Type,
 53            descriptor.DisplayName,
 54            descriptor.IsSerializable,
 55            descriptor.IsBrowsable,
 56            properties);
 57    }
 58}
 59
 060internal record ExpressionDescriptorModel(string Type, string DisplayName, bool IsSerializable, bool IsBrowsable, IDicti

Methods/Properties

get_Type()