mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
71 lines
2.5 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using Squidex.Domain.Apps.Core.Contents;
|
|
using Squidex.Domain.Apps.Entities.Apps.Commands;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Apps.Guards
|
|
{
|
|
public static class GuardAppWorkflows
|
|
{
|
|
public static void CanConfigure(ConfigureWorkflow command)
|
|
{
|
|
Guard.NotNull(command, nameof(command));
|
|
|
|
Validate.It(() => "Cannot configure workflow.", e =>
|
|
{
|
|
if (command.Workflow == null)
|
|
{
|
|
e(Not.Defined("Workflow"), nameof(command.Workflow));
|
|
return;
|
|
}
|
|
|
|
var workflow = command.Workflow;
|
|
|
|
if (!workflow.Steps.ContainsKey(workflow.Initial))
|
|
{
|
|
e(Not.Defined("Initial step"), $"{nameof(command.Workflow)}.{nameof(workflow.Initial)}");
|
|
}
|
|
|
|
var stepsPrefix = $"{nameof(command.Workflow)}.{nameof(workflow.Steps)}";
|
|
|
|
if (!workflow.Steps.ContainsKey(Status.Published))
|
|
{
|
|
e("Workflow must have a published step.", stepsPrefix);
|
|
}
|
|
|
|
foreach (var step in workflow.Steps)
|
|
{
|
|
var stepPrefix = $"{stepsPrefix}.{step.Key}";
|
|
|
|
if (step.Value == null)
|
|
{
|
|
e(Not.Defined("Step"), stepPrefix);
|
|
}
|
|
else
|
|
{
|
|
foreach (var transition in step.Value.Transitions)
|
|
{
|
|
var transitionPrefix = $"{stepPrefix}.{nameof(step.Value.Transitions)}.{transition.Key}";
|
|
|
|
if (!workflow.Steps.ContainsKey(transition.Key))
|
|
{
|
|
e("Transition has an invalid target.", transitionPrefix);
|
|
}
|
|
|
|
if (transition.Value == null)
|
|
{
|
|
e(Not.Defined("Transition"), transitionPrefix);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|