Browse Source

Ensure that initial state is not published.

pull/380/head
Sebastian Stehle 7 years ago
parent
commit
cf480c114f
  1. 5
      src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppWorkflows.cs
  2. 2
      src/Squidex/app/features/administration/services/users.service.ts
  3. 33
      tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppWorkflowTests.cs

5
src/Squidex.Domain.Apps.Entities/Apps/Guards/GuardAppWorkflows.cs

@ -32,6 +32,11 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
e(Not.Defined("Initial step"), $"{nameof(command.Workflow)}.{nameof(workflow.Initial)}");
}
if (workflow.Initial == Status.Published)
{
e("Initial step cannot be published step.", $"{nameof(command.Workflow)}.{nameof(workflow.Initial)}");
}
var stepsPrefix = $"{nameof(command.Workflow)}.{nameof(workflow.Steps)}";
if (!workflow.Steps.ContainsKey(Status.Published))

2
src/Squidex/app/features/administration/services/users.service.ts

@ -19,7 +19,7 @@ import {
ResultSet
} from '@app/shared';
export class UsersDto extends ResultSet<UserDto> {
export class UsersDto extends ResultSet<UserDto> {
public get canCreate() {
return hasAnyLink(this._links, 'create');
}

33
tests/Squidex.Domain.Apps.Entities.Tests/Apps/Guards/GuardAppWorkflowTests.cs

@ -42,6 +42,23 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
new ValidationError("Initial step is required.", "Workflow.Initial"));
}
[Fact]
public void CanConfigure_should_throw_exception_if_initial_step_is_published()
{
var command = new ConfigureWorkflow
{
Workflow = new Workflow(
new Dictionary<Status, WorkflowStep>
{
[Status.Published] = new WorkflowStep()
},
Status.Published)
};
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
new ValidationError("Initial step cannot be published step.", "Workflow.Initial"));
}
[Fact]
public void CanConfigure_should_throw_exception_if_workflow_does_not_have_published_state()
{
@ -67,9 +84,10 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
Workflow = new Workflow(
new Dictionary<Status, WorkflowStep>
{
[Status.Published] = null
[Status.Published] = null,
[Status.Draft] = new WorkflowStep()
},
Status.Published)
Status.Draft)
};
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
@ -88,14 +106,15 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
new WorkflowStep(
new Dictionary<Status, WorkflowTransition>
{
[Status.Draft] = new WorkflowTransition()
})
[Status.Archived] = new WorkflowTransition()
}),
[Status.Draft] = new WorkflowStep()
},
Status.Published)
Status.Draft)
};
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),
new ValidationError("Transition has an invalid target.", "Workflow.Steps.Published.Transitions.Draft"));
new ValidationError("Transition has an invalid target.", "Workflow.Steps.Published.Transitions.Archived"));
}
[Fact]
@ -115,7 +134,7 @@ namespace Squidex.Domain.Apps.Entities.Apps.Guards
[Status.Draft] = null
})
},
Status.Published)
Status.Draft)
};
ValidationAssert.Throws(() => GuardAppWorkflows.CanConfigure(command),

Loading…
Cancel
Save