// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using Squidex.Domain.Apps.Core.Contents; using Squidex.Infrastructure.Reflection; using Squidex.Shared; using Squidex.Web; namespace Squidex.Areas.Api.Controllers.Apps.Models { public sealed class WorkflowDto : Resource { /// /// The workflow id. /// public Guid Id { get; set; } /// /// The name of the workflow. /// public string Name { get; set; } /// /// The workflow steps. /// [Required] public Dictionary Steps { get; set; } /// /// The schema ids. /// public IReadOnlyList SchemaIds { get; set; } /// /// The initial step. /// public Status Initial { get; set; } public static WorkflowDto FromWorkflow(Guid id, Workflow workflow, ApiController controller, string app) { var result = SimpleMapper.Map(workflow, new WorkflowDto { Steps = workflow.Steps.ToDictionary( x => x.Key, x => WorkflowStepDto.FromWorkflowStep(x.Value)), Id = id }); return result.CreateLinks(controller, app, id); } private WorkflowDto CreateLinks(ApiController controller, string app, Guid id) { var values = new { app, id }; if (controller.HasPermission(Permissions.AppWorkflowsUpdate, app)) { AddPutLink("update", controller.Url(x => nameof(x.PutWorkflow), values)); } if (controller.HasPermission(Permissions.AppWorkflowsDelete, app)) { AddDeleteLink("delete", controller.Url(x => nameof(x.DeleteWorkflow), values)); } return this; } } }