Browse Source

Fix 500 when saving workflows.

pull/400/head
Sebastian Stehle 6 years ago
parent
commit
154a39b59e
  1. 7
      src/Squidex/Areas/Api/Controllers/Apps/Models/UpdateWorkflowDto.cs
  2. 15
      src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowDto.cs
  3. 26
      src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowStepDto.cs
  4. 17
      src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowTransitionDto.cs

7
src/Squidex/Areas/Api/Controllers/Apps/Models/UpdateWorkflowDto.cs

@ -43,12 +43,7 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models
Initial, Initial,
Steps?.ToDictionary( Steps?.ToDictionary(
x => x.Key, x => x.Key,
x => new WorkflowStep( x => x.Value?.ToStep()),
x.Value?.Transitions.ToDictionary(
y => y.Key,
y => new WorkflowTransition(y.Value.Expression, y.Value.Role)),
x.Value.Color,
x.Value.NoUpdate)),
SchemaIds, SchemaIds,
Name); Name);

15
src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowDto.cs

@ -46,16 +46,13 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models
public static WorkflowDto FromWorkflow(Guid id, Workflow workflow, ApiController controller, string app) public static WorkflowDto FromWorkflow(Guid id, Workflow workflow, ApiController controller, string app)
{ {
var result = SimpleMapper.Map(workflow, new WorkflowDto { Id = id }); var result = SimpleMapper.Map(workflow, new WorkflowDto
result.Steps = workflow.Steps.ToDictionary(
x => x.Key,
x => SimpleMapper.Map(x.Value, new WorkflowStepDto
{ {
Transitions = x.Value.Transitions.ToDictionary( Steps = workflow.Steps.ToDictionary(
y => y.Key, x => x.Key,
y => new WorkflowTransitionDto { Expression = y.Value.Expression, Role = y.Value.Role }) x => WorkflowStepDto.FromWorkflowStep(x.Value)),
})); Id = id
});
return result.CreateLinks(controller, app, id); return result.CreateLinks(controller, app, id);
} }

26
src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowStepDto.cs

@ -7,7 +7,9 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq;
using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.Contents;
using Squidex.Infrastructure.Reflection;
namespace Squidex.Areas.Api.Controllers.Apps.Models namespace Squidex.Areas.Api.Controllers.Apps.Models
{ {
@ -28,5 +30,29 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models
/// Indicates if updates should not be allowed. /// Indicates if updates should not be allowed.
/// </summary> /// </summary>
public bool NoUpdate { get; set; } public bool NoUpdate { get; set; }
public static WorkflowStepDto FromWorkflowStep(WorkflowStep step)
{
if (step == null)
{
return null;
}
return SimpleMapper.Map(step, new WorkflowStepDto
{
Transitions = step.Transitions.ToDictionary(
y => y.Key,
y => WorkflowTransitionDto.FromWorkflowTransition(y.Value))
});
}
public WorkflowStep ToStep()
{
return new WorkflowStep(
Transitions?.ToDictionary(
y => y.Key,
y => y.Value?.ToTransition()),
Color, NoUpdate);
}
} }
} }

17
src/Squidex/Areas/Api/Controllers/Apps/Models/WorkflowTransitionDto.cs

@ -5,6 +5,8 @@
// All rights reserved. Licensed under the MIT license. // All rights reserved. Licensed under the MIT license.
// ========================================================================== // ==========================================================================
using Squidex.Domain.Apps.Core.Contents;
namespace Squidex.Areas.Api.Controllers.Apps.Models namespace Squidex.Areas.Api.Controllers.Apps.Models
{ {
public sealed class WorkflowTransitionDto public sealed class WorkflowTransitionDto
@ -18,5 +20,20 @@ namespace Squidex.Areas.Api.Controllers.Apps.Models
/// The optional restricted role. /// The optional restricted role.
/// </summary> /// </summary>
public string Role { get; set; } public string Role { get; set; }
public static WorkflowTransitionDto FromWorkflowTransition(WorkflowTransition transition)
{
if (transition == null)
{
return null;
}
return new WorkflowTransitionDto { Expression = transition.Expression, Role = transition.Role };
}
public WorkflowTransition ToTransition()
{
return new WorkflowTransition(Expression, Role);
}
} }
} }

Loading…
Cancel
Save