< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Delete.Delete
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Delete/Endpoint.cs
Line coverage
18%
Covered lines: 4
Uncovered lines: 18
Coverable lines: 22
Total lines: 51
Line coverage: 18.1%
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/Delete/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 Microsoft.AspNetCore.Authorization;
 8
 9namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Delete;
 10
 111internal class Delete(IWorkflowDefinitionManager workflowDefinitionManager, IAuthorizationService authorizationService, 
 12    : ElsaEndpoint<Request>
 13{
 14    public override void Configure()
 15    {
 116        Delete("/workflow-definitions/{definitionId}");
 117        ConfigurePermissions("delete:workflow-definitions");
 118    }
 19
 20    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 21    {
 022        var filter = new WorkflowDefinitionFilter
 023        {
 024            DefinitionId = request.DefinitionId,
 025            VersionOptions = VersionOptions.Latest
 026        };
 27
 028        var definition = await store.FindAsync(filter, cancellationToken);
 29
 030        if (definition == null)
 31        {
 032            await Send.NotFoundAsync(cancellationToken);
 033            return;
 34        }
 35
 036        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A
 37
 038        if (!authorizationResult.Succeeded)
 39        {
 040            await Send.ForbiddenAsync(cancellationToken);
 041            return;
 42        }
 43
 044        var result = await workflowDefinitionManager.DeleteByDefinitionIdAsync(request.DefinitionId, cancellationToken);
 45
 046        if (result == 0)
 047            await Send.NotFoundAsync(cancellationToken);
 48        else
 049            await Send.NoContentAsync(cancellationToken);
 050    }
 51}