< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Retract.Retract
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Retract/Endpoint.cs
Line coverage
16%
Covered lines: 4
Uncovered lines: 21
Coverable lines: 25
Total lines: 58
Line coverage: 16%
Branch coverage
0%
Covered branches: 0
Total branches: 6
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%4260%

File(s)

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

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Models;
 3using Elsa.Workflows.Api.Constants;
 4using Elsa.Workflows.Api.Models;
 5using Elsa.Workflows.Api.Requirements;
 6using Elsa.Workflows.Management;
 7using Elsa.Workflows.Management.Filters;
 8using JetBrains.Annotations;
 9using Microsoft.AspNetCore.Authorization;
 10
 11namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Retract;
 12
 13[PublicAPI]
 114internal class Retract(IWorkflowDefinitionStore store, IWorkflowDefinitionPublisher workflowDefinitionPublisher, IWorkfl
 15    : ElsaEndpoint<Request, LinkedWorkflowDefinitionModel>
 16{
 17    public override void Configure()
 18    {
 119        Post("/workflow-definitions/{definitionId}/retract");
 120        ConfigurePermissions("retract:workflow-definitions");
 121    }
 22
 23    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 24    {
 025        var filter = new WorkflowDefinitionFilter
 026        {
 027            DefinitionId = request.DefinitionId,
 028            VersionOptions = VersionOptions.LatestOrPublished
 029        };
 30
 031        var definition = await store.FindAsync(filter, cancellationToken);
 32
 033        if (definition == null)
 34        {
 035            await Send.NotFoundAsync(cancellationToken);
 036            return;
 37        }
 38
 039        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A
 40
 041        if (!authorizationResult.Succeeded)
 42        {
 043            await Send.ForbiddenAsync(cancellationToken);
 044            return;
 45        }
 46
 047        if (!definition.IsPublished)
 48        {
 049            AddError($"Workflow with id {request.DefinitionId} is not published");
 050            await Send.ErrorsAsync(cancellation: cancellationToken);
 051            return;
 52        }
 53
 054        await workflowDefinitionPublisher.RetractAsync(definition, cancellationToken);
 055        var response = await linker.MapAsync(definition, cancellationToken);
 056        await Send.OkAsync(response, cancellationToken);
 057    }
 58}