| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Workflows.Management; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Export; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Exports the specified workflow definition as JSON download. |
| | | 11 | | /// </summary> |
| | | 12 | | [UsedImplicitly] |
| | 7 | 13 | | internal class Export(IWorkflowDefinitionExporter exporter) : ElsaEndpoint<Request> |
| | | 14 | | { |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public override void Configure() |
| | | 17 | | { |
| | 3 | 18 | | Routes("/bulk-actions/export/workflow-definitions", "/workflow-definitions/{definitionId}/export"); |
| | 3 | 19 | | Verbs(FastEndpoints.Http.GET, FastEndpoints.Http.POST); |
| | 3 | 20 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Definitions, CoreVerbs.View); |
| | 3 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 25 | | { |
| | 4 | 26 | | if (request.DefinitionId != null) |
| | | 27 | | { |
| | 2 | 28 | | var versionOptions = string.IsNullOrEmpty(request.VersionOptions) ? VersionOptions.Latest : VersionOptions.F |
| | 2 | 29 | | var result = await exporter.ExportAsync(request.DefinitionId, versionOptions, request.IncludeConsumingWorkfl |
| | | 30 | | |
| | 2 | 31 | | if (result == null) |
| | | 32 | | { |
| | 0 | 33 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 34 | | return; |
| | | 35 | | } |
| | | 36 | | |
| | 2 | 37 | | await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken); |
| | | 38 | | } |
| | 2 | 39 | | else if (request.Ids != null) |
| | | 40 | | { |
| | 2 | 41 | | var result = await exporter.ExportManyAsync(request.Ids, request.IncludeConsumingWorkflows, cancellationToke |
| | | 42 | | |
| | 2 | 43 | | if (result == null) |
| | | 44 | | { |
| | 0 | 45 | | await Send.NoContentAsync(cancellationToken); |
| | 0 | 46 | | return; |
| | | 47 | | } |
| | | 48 | | |
| | 2 | 49 | | await Send.BytesAsync(result.Data, result.FileName, cancellation: cancellationToken); |
| | | 50 | | } |
| | | 51 | | else |
| | | 52 | | { |
| | 0 | 53 | | await Send.NoContentAsync(cancellationToken); |
| | | 54 | | } |
| | 4 | 55 | | } |
| | | 56 | | } |