< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Version.DeleteVersion
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Version/Delete.cs
Line coverage
16%
Covered lines: 4
Uncovered lines: 21
Coverable lines: 25
Total lines: 63
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/Version/Delete.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.Version;
 11
 12/// <summary>
 13/// Deletes a specific version of a workflow definition.
 14/// </summary>
 15[PublicAPI]
 116public class DeleteVersion(IWorkflowDefinitionManager workflowDefinitionManager, IWorkflowDefinitionStore store, IAuthor
 17{
 18    /// <inheritdoc />
 19    public override void Configure()
 20    {
 121        Delete("workflow-definitions/{definitionId}/version/{version}");
 122        ConfigurePermissions("delete:workflow-definitions");
 123    }
 24
 25    /// <inheritdoc />
 26    public override async Task HandleAsync(CancellationToken cancellationToken)
 27    {
 028        var definitionId = Route<string>("definitionId")!;
 029        var version = Route<int>("version");
 30
 031        var filter = new WorkflowDefinitionFilter
 032        {
 033            DefinitionId = definitionId,
 034            VersionOptions = VersionOptions.SpecificVersion(version)
 035        };
 36
 037        var definition = await store.FindAsync(filter, cancellationToken);
 38
 039        if (definition == null)
 40        {
 041            await Send.NotFoundAsync(cancellationToken);
 042            return;
 43        }
 44
 045        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A
 46
 047        if (!authorizationResult.Succeeded)
 48        {
 049            await Send.ForbiddenAsync(cancellationToken);
 050            return;
 51        }
 52
 053        var result = await workflowDefinitionManager.DeleteVersionAsync(definition, cancellationToken);
 54
 055        if (!result)
 56        {
 057            await Send.NotFoundAsync(cancellationToken);
 058            return;
 59        }
 60
 061        await Send.OkAsync(cancellationToken);
 062    }
 63}