| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Workflows.Api.Constants; |
| | | 4 | | using Elsa.Workflows.Api.Requirements; |
| | | 5 | | using Elsa.Workflows.Management; |
| | | 6 | | using Elsa.Workflows.Management.Filters; |
| | | 7 | | using JetBrains.Annotations; |
| | | 8 | | using Microsoft.AspNetCore.Authorization; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Version; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Deletes a specific version of a workflow definition. |
| | | 14 | | /// </summary> |
| | | 15 | | [PublicAPI] |
| | 1 | 16 | | public class DeleteVersion(IWorkflowDefinitionManager workflowDefinitionManager, IWorkflowDefinitionStore store, IAuthor |
| | | 17 | | { |
| | | 18 | | /// <inheritdoc /> |
| | | 19 | | public override void Configure() |
| | | 20 | | { |
| | 1 | 21 | | Delete("workflow-definitions/{definitionId}/version/{version}"); |
| | 1 | 22 | | ConfigurePermissions("delete:workflow-definitions"); |
| | 1 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <inheritdoc /> |
| | | 26 | | public override async Task HandleAsync(CancellationToken cancellationToken) |
| | | 27 | | { |
| | 0 | 28 | | var definitionId = Route<string>("definitionId")!; |
| | 0 | 29 | | var version = Route<int>("version"); |
| | | 30 | | |
| | 0 | 31 | | var filter = new WorkflowDefinitionFilter |
| | 0 | 32 | | { |
| | 0 | 33 | | DefinitionId = definitionId, |
| | 0 | 34 | | VersionOptions = VersionOptions.SpecificVersion(version) |
| | 0 | 35 | | }; |
| | | 36 | | |
| | 0 | 37 | | var definition = await store.FindAsync(filter, cancellationToken); |
| | | 38 | | |
| | 0 | 39 | | if (definition == null) |
| | | 40 | | { |
| | 0 | 41 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 42 | | return; |
| | | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A |
| | | 46 | | |
| | 0 | 47 | | if (!authorizationResult.Succeeded) |
| | | 48 | | { |
| | 0 | 49 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 50 | | return; |
| | | 51 | | } |
| | | 52 | | |
| | 0 | 53 | | var result = await workflowDefinitionManager.DeleteVersionAsync(definition, cancellationToken); |
| | | 54 | | |
| | 0 | 55 | | if (!result) |
| | | 56 | | { |
| | 0 | 57 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 58 | | return; |
| | | 59 | | } |
| | | 60 | | |
| | 0 | 61 | | await Send.OkAsync(cancellationToken); |
| | 0 | 62 | | } |
| | | 63 | | } |