| | | 1 | | using Elsa.Authorization; |
| | | 2 | | using Elsa.Abstractions; |
| | | 3 | | using Elsa.Common.Models; |
| | | 4 | | using Elsa.Workflows.Api.Constants; |
| | | 5 | | using Elsa.Workflows.Api.Requirements; |
| | | 6 | | using Elsa.Workflows.Management; |
| | | 7 | | using Elsa.Workflows.Management.Contracts; |
| | | 8 | | using Elsa.Workflows.Management.Filters; |
| | | 9 | | using JetBrains.Annotations; |
| | | 10 | | using Microsoft.AspNetCore.Authorization; |
| | | 11 | | |
| | | 12 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.UpdateReferences; |
| | | 13 | | |
| | | 14 | | [PublicAPI] |
| | 3 | 15 | | internal class UpdateReferences(IWorkflowReferenceUpdater workflowReferenceUpdater, IWorkflowDefinitionStore store, IAut |
| | | 16 | | : ElsaEndpoint<Request, Response> |
| | | 17 | | { |
| | | 18 | | public override void Configure() |
| | | 19 | | { |
| | 3 | 20 | | Post("/workflow-definitions/{definitionId}/update-references"); |
| | 3 | 21 | | RequirePermission(Elsa.Workflows.Api.Permissions.WorkflowPermissions.Definitions, "publish"); |
| | 3 | 22 | | } |
| | | 23 | | |
| | | 24 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 25 | | { |
| | 0 | 26 | | var filter = new WorkflowDefinitionFilter |
| | 0 | 27 | | { |
| | 0 | 28 | | DefinitionId = request.DefinitionId, |
| | 0 | 29 | | VersionOptions = VersionOptions.Latest |
| | 0 | 30 | | }; |
| | | 31 | | |
| | 0 | 32 | | var definition = await store.FindAsync(filter, cancellationToken); |
| | | 33 | | |
| | 0 | 34 | | if (definition == null) |
| | | 35 | | { |
| | 0 | 36 | | await Send.NotFoundAsync(cancellationToken); |
| | 0 | 37 | | return; |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A |
| | | 41 | | |
| | 0 | 42 | | if (!authorizationResult.Succeeded) |
| | | 43 | | { |
| | 0 | 44 | | await Send.ForbiddenAsync(cancellationToken); |
| | 0 | 45 | | return; |
| | | 46 | | } |
| | | 47 | | |
| | 0 | 48 | | var result = await workflowReferenceUpdater.UpdateWorkflowReferencesAsync(definition, cancellationToken); |
| | 0 | 49 | | var affectedWorkflows = result.UpdatedWorkflows; |
| | 0 | 50 | | var response = new Response(affectedWorkflows.Select(w => w.Name ?? w.DefinitionId)); |
| | 0 | 51 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 52 | | } |
| | | 53 | | } |