| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Api.Endpoints.ActivityDescriptorOptions.Get; |
| | | 6 | | |
| | | 7 | | [PublicAPI] |
| | | 8 | | internal class Get : ElsaEndpoint<Request, Response> |
| | | 9 | | { |
| | | 10 | | private readonly IServiceProvider _serviceProvider; |
| | | 11 | | private readonly IActivityRegistryLookupService _registryLookup; |
| | | 12 | | private readonly IPropertyUIHandlerResolver _optionsResolver; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | 3 | 15 | | public Get(IServiceProvider serviceProvider, IActivityRegistryLookupService registryLookup, IPropertyUIHandlerResolv |
| | | 16 | | { |
| | 3 | 17 | | _serviceProvider = serviceProvider; |
| | 3 | 18 | | _registryLookup = registryLookup; |
| | 3 | 19 | | _optionsResolver = optionsResolver; |
| | 3 | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <inheritdoc /> |
| | | 23 | | public override void Configure() |
| | | 24 | | { |
| | 3 | 25 | | Post("/descriptors/activities/{activityTypeName}/options/{propertyName}"); |
| | 3 | 26 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.DescriptorsActivities, CoreVerbs.View); |
| | 3 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <inheritdoc /> |
| | | 30 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 31 | | { |
| | 0 | 32 | | var descriptor = request.Version == null ? await _registryLookup.FindAsync(request.ActivityTypeName) : await _re |
| | 0 | 33 | | if (descriptor == null) |
| | 0 | 34 | | await Send.NotFoundAsync(cancellationToken); |
| | | 35 | | |
| | 0 | 36 | | var propertyDescriptor = descriptor!.Inputs.FirstOrDefault(x => x.Name == request.PropertyName); |
| | | 37 | | |
| | 0 | 38 | | if(propertyDescriptor == null) |
| | | 39 | | { |
| | 0 | 40 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 41 | | return; |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | var inputOptions = await _optionsResolver.GetUIPropertiesAsync(propertyDescriptor.PropertyInfo!, request.Context |
| | | 45 | | |
| | 0 | 46 | | await Send.OkAsync(new Response(inputOptions), cancellationToken); |
| | 0 | 47 | | } |
| | | 48 | | } |