| | | 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 Microsoft.AspNetCore.Authorization; |
| | | 8 | | |
| | | 9 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Delete; |
| | | 10 | | |
| | 1 | 11 | | internal class Delete(IWorkflowDefinitionManager workflowDefinitionManager, IAuthorizationService authorizationService, |
| | | 12 | | : ElsaEndpoint<Request> |
| | | 13 | | { |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | 1 | 16 | | Delete("/workflow-definitions/{definitionId}"); |
| | 1 | 17 | | ConfigurePermissions("delete:workflow-definitions"); |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 21 | | { |
| | 0 | 22 | | var filter = new WorkflowDefinitionFilter |
| | 0 | 23 | | { |
| | 0 | 24 | | DefinitionId = request.DefinitionId, |
| | 0 | 25 | | VersionOptions = VersionOptions.Latest |
| | 0 | 26 | | }; |
| | | 27 | | |
| | 0 | 28 | | var definition = await store.FindAsync(filter, cancellationToken); |
| | | 29 | | |
| | 0 | 30 | | if (definition == null) |
| | | 31 | | { |
| | 0 | 32 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 33 | | return; |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A |
| | | 37 | | |
| | 0 | 38 | | if (!authorizationResult.Succeeded) |
| | | 39 | | { |
| | 0 | 40 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 41 | | return; |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | var result = await workflowDefinitionManager.DeleteByDefinitionIdAsync(request.DefinitionId, cancellationToken); |
| | | 45 | | |
| | 0 | 46 | | if (result == 0) |
| | 0 | 47 | | await Send.NotFoundAsync(cancellationToken); |
| | | 48 | | else |
| | 0 | 49 | | await Send.NoContentAsync(cancellationToken); |
| | 0 | 50 | | } |
| | | 51 | | } |