< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Publish.Publish
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs
Line coverage
17%
Covered lines: 4
Uncovered lines: 19
Coverable lines: 23
Total lines: 52
Line coverage: 17.3%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()0%7280%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Publish/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Models;
 3using Elsa.Workflows.Api.Constants;
 4using Elsa.Workflows.Api.Requirements;
 5using Elsa.Workflows.Management;
 6using Elsa.Workflows.Management.Filters;
 7using JetBrains.Annotations;
 8using Microsoft.AspNetCore.Authorization;
 9
 10namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Publish;
 11
 12[PublicAPI]
 113internal class Publish(IWorkflowDefinitionStore store, IWorkflowDefinitionPublisher workflowDefinitionPublisher, IWorkfl
 14    : ElsaEndpoint<Request, Response>
 15{
 16    public override void Configure()
 17    {
 118        Post("/workflow-definitions/{definitionId}/publish");
 119        ConfigurePermissions("publish:workflow-definitions");
 120    }
 21
 22    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 23    {
 024        var filter = new WorkflowDefinitionFilter
 025        {
 026            DefinitionId = request.DefinitionId,
 027            VersionOptions = VersionOptions.Latest
 028        };
 29
 030        var definition = await store.FindAsync(filter, cancellationToken);
 31
 032        if (definition == null)
 33        {
 034            await Send.NotFoundAsync(cancellationToken);
 035            return;
 36        }
 37
 038        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A
 39
 040        if (!authorizationResult.Succeeded)
 41        {
 042            await Send.ForbiddenAsync(cancellationToken);
 043            return;
 44        }
 45
 046        var isPublished = definition.IsPublished;
 047        var result = !isPublished ? await workflowDefinitionPublisher.PublishAsync(definition, cancellationToken) : null
 048        var mappedDefinition = await linker.MapAsync(definition, cancellationToken);
 049        var response = new Response(mappedDefinition, isPublished, result?.AffectedWorkflows.WorkflowDefinitions.Count ?
 050        await Send.OkAsync(response, cancellationToken);
 051    }
 52}