-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6342 from elsa-workflows/vaidate-unique-input-output
Validate unique input/output names before publishing workflow
- Loading branch information
Showing
5 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/modules/Elsa.Workflows.Management/Handlers/Notification/ValidateWorkflow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Elsa.Mediator.Contracts; | ||
using Elsa.Workflows.Management.Models; | ||
using Elsa.Workflows.Management.Notifications; | ||
using Elsa.Workflows.Models; | ||
|
||
namespace Elsa.Workflows.Management.Handlers.Notification; | ||
|
||
public class ValidateWorkflow : INotificationHandler<WorkflowDefinitionValidating> | ||
{ | ||
public Task HandleAsync(WorkflowDefinitionValidating notification, CancellationToken cancellationToken) | ||
{ | ||
var workflow = notification.Workflow; | ||
var inputs = workflow.Inputs; | ||
var outputs = workflow.Outputs; | ||
|
||
ValidateUniqueNames(inputs, "inputs", notification.ValidationErrors); | ||
ValidateUniqueNames(outputs, "outputs", notification.ValidationErrors); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private void ValidateUniqueNames(IEnumerable<ArgumentDefinition> variables, string variableType, ICollection<WorkflowValidationError> validationErrors) | ||
{ | ||
var duplicateNames = variables.GroupBy(x => x.Name).Where(x => x.Count() > 1).Select(x => x.Key).ToList(); | ||
if (duplicateNames.Any()) | ||
{ | ||
var message = $"The following {variableType} are defined more than once: {string.Join(", ", duplicateNames)}"; | ||
validationErrors.Add(new(message)); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters