| | | 1 | | using Elsa.Http.Bookmarks; |
| | | 2 | | using Elsa.Workflows.Activities; |
| | | 3 | | using Elsa.Workflows.Helpers; |
| | | 4 | | using Elsa.Workflows.Management.Models; |
| | | 5 | | using Elsa.Workflows.Runtime; |
| | | 6 | | using Elsa.Workflows.Runtime.Contracts; |
| | | 7 | | using Elsa.Workflows.Runtime.Entities; |
| | | 8 | | using Elsa.Workflows.Runtime.Filters; |
| | | 9 | | |
| | | 10 | | namespace Elsa.Http.TriggerPayloadValidators; |
| | | 11 | | |
| | 4 | 12 | | public class HttpEndpointTriggerPayloadValidator(ITriggerStore triggerStore) : ITriggerPayloadValidator<HttpEndpointBook |
| | | 13 | | { |
| | | 14 | | public async Task ValidateAsync( |
| | | 15 | | HttpEndpointBookmarkPayload payload, |
| | | 16 | | Workflow workflow, |
| | | 17 | | StoredTrigger trigger, |
| | | 18 | | ICollection<WorkflowValidationError> validationErrors, |
| | | 19 | | CancellationToken cancellationToken) |
| | | 20 | | { |
| | 8 | 21 | | var filter = new TriggerFilter |
| | 8 | 22 | | { |
| | 8 | 23 | | Name = ActivityTypeNameHelper.GenerateTypeName(typeof(HttpEndpoint)) |
| | 8 | 24 | | }; |
| | 8 | 25 | | var publishedWorkflowsTriggers = (await triggerStore.FindManyAsync(filter, cancellationToken)).ToList(); |
| | | 26 | | |
| | 8 | 27 | | var otherWorkflowsWithSamePath = publishedWorkflowsTriggers |
| | 8 | 28 | | .Where(x => |
| | 18 | 29 | | x.WorkflowDefinitionId != workflow.Identity.DefinitionId && |
| | 18 | 30 | | x.Payload is HttpEndpointBookmarkPayload anotherHttpEndpointPayload && |
| | 18 | 31 | | anotherHttpEndpointPayload.Path == payload.Path && |
| | 18 | 32 | | anotherHttpEndpointPayload.Method == payload.Method) |
| | 8 | 33 | | .ToList(); |
| | | 34 | | |
| | 8 | 35 | | if (otherWorkflowsWithSamePath.Count == 0) |
| | 6 | 36 | | return; |
| | | 37 | | |
| | 2 | 38 | | validationErrors.Add(new($"The {payload.Path} path and {payload.Method} method are already in use by another wor |
| | 2 | 39 | | trigger.ActivityId)); |
| | 8 | 40 | | } |
| | | 41 | | } |