| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Workflows.Api.Constants; |
| | | 3 | | using Elsa.Workflows.Api.Requirements; |
| | | 4 | | using Elsa.Workflows.Management; |
| | | 5 | | using JetBrains.Annotations; |
| | | 6 | | using Microsoft.AspNetCore.Authorization; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.DeleteVersion; |
| | | 9 | | |
| | | 10 | | [PublicAPI] |
| | 1 | 11 | | internal class DeleteVersion(IWorkflowDefinitionManager workflowDefinitionManager, IAuthorizationService authorizationSe |
| | | 12 | | : ElsaEndpoint<Request> |
| | | 13 | | { |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | 1 | 16 | | Delete("/workflow-definition-versions/{id}"); |
| | 1 | 17 | | ConfigurePermissions("delete:workflow-definitions"); |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 21 | | { |
| | 0 | 22 | | var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(), Authorizati |
| | | 23 | | |
| | 0 | 24 | | if (!authorizationResult.Succeeded) |
| | | 25 | | { |
| | 0 | 26 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 27 | | return; |
| | | 28 | | } |
| | | 29 | | |
| | 0 | 30 | | var deleted = await workflowDefinitionManager.DeleteByIdAsync(request.Id, cancellationToken); |
| | | 31 | | |
| | 0 | 32 | | if (!deleted) |
| | 0 | 33 | | await Send.NotFoundAsync(cancellationToken); |
| | | 34 | | else |
| | 0 | 35 | | await Send.NoContentAsync(cancellationToken); |
| | 0 | 36 | | } |
| | | 37 | | } |