< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Version.RevertVersion
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Version/Revert.cs
Line coverage
15%
Covered lines: 4
Uncovered lines: 22
Coverable lines: 26
Total lines: 58
Line coverage: 15.3%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/Version/Revert.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 Elsa.Workflows.Management.Models;
 8using JetBrains.Annotations;
 9using Microsoft.AspNetCore.Authorization;
 10
 11namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.Version;
 12
 13[PublicAPI]
 114internal class RevertVersion(IWorkflowDefinitionManager workflowDefinitionManager, IAuthorizationService authorizationSe
 15    : ElsaEndpointWithoutRequest
 16{
 17    public override void Configure()
 18    {
 119        Post("workflow-definitions/{definitionId}/revert/{version}");
 120        ConfigurePermissions("publish:workflow-definitions");
 121    }
 22
 23    public override async Task HandleAsync(CancellationToken cancellationToken)
 24    {
 025        var definitionId = Route<string>("definitionId")!;
 026        var version = Route<int>("version");
 27
 028        var filter = new WorkflowDefinitionFilter
 029        {
 030            DefinitionId = definitionId,
 031            VersionOptions = VersionOptions.SpecificVersion(version)
 032        };
 33
 034        var definition = await store.FindAsync(filter, cancellationToken);
 35
 036        if (definition == null)
 37        {
 038            await Send.NotFoundAsync(cancellationToken);
 039            return;
 40        }
 41
 042        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(definition), A
 43
 044        if (!authorizationResult.Succeeded)
 45        {
 046            await Send.ForbiddenAsync(cancellationToken);
 047            return;
 48        }
 49
 050        var newDefinition = await workflowDefinitionManager.RevertVersionAsync(definitionId, version, cancellationToken)
 051        var newDefinitionSummary = WorkflowDefinitionSummary.FromDefinition(newDefinition);
 52
 053        await Send.CreatedAtAsync("GetWorkflowDefinitionById", new
 054        {
 055            id = newDefinition.Id
 056        }, newDefinitionSummary, cancellation: cancellationToken);
 057    }
 58}