| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Workflows.Api.Constants; |
| | | 4 | | using Elsa.Workflows.Api.Models; |
| | | 5 | | using Elsa.Workflows.Api.Requirements; |
| | | 6 | | using Elsa.Workflows.Management; |
| | | 7 | | using Elsa.Workflows.Management.Filters; |
| | | 8 | | using JetBrains.Annotations; |
| | | 9 | | using Microsoft.AspNetCore.Authorization; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Retract; |
| | | 12 | | |
| | | 13 | | [PublicAPI] |
| | 1 | 14 | | internal class Retract(IWorkflowDefinitionStore store, IWorkflowDefinitionPublisher workflowDefinitionPublisher, IWorkfl |
| | | 15 | | : ElsaEndpoint<Request, LinkedWorkflowDefinitionModel> |
| | | 16 | | { |
| | | 17 | | public override void Configure() |
| | | 18 | | { |
| | 1 | 19 | | Post("/workflow-definitions/{definitionId}/retract"); |
| | 1 | 20 | | ConfigurePermissions("retract:workflow-definitions"); |
| | 1 | 21 | | } |
| | | 22 | | |
| | | 23 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 24 | | { |
| | 0 | 25 | | var filter = new WorkflowDefinitionFilter |
| | 0 | 26 | | { |
| | 0 | 27 | | DefinitionId = request.DefinitionId, |
| | 0 | 28 | | VersionOptions = VersionOptions.LatestOrPublished |
| | 0 | 29 | | }; |
| | | 30 | | |
| | 0 | 31 | | var definition = await store.FindAsync(filter, cancellationToken); |
| | | 32 | | |
| | 0 | 33 | | if (definition == null) |
| | | 34 | | { |
| | 0 | 35 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 36 | | return; |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A |
| | | 40 | | |
| | 0 | 41 | | if (!authorizationResult.Succeeded) |
| | | 42 | | { |
| | 0 | 43 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 44 | | return; |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | if (!definition.IsPublished) |
| | | 48 | | { |
| | 0 | 49 | | AddError($"Workflow with id {request.DefinitionId} is not published"); |
| | 0 | 50 | | await Send.ErrorsAsync(cancellation: cancellationToken); |
| | 0 | 51 | | return; |
| | | 52 | | } |
| | | 53 | | |
| | 0 | 54 | | await workflowDefinitionPublisher.RetractAsync(definition, cancellationToken); |
| | 0 | 55 | | var response = await linker.MapAsync(definition, cancellationToken); |
| | 0 | 56 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 57 | | } |
| | | 58 | | } |