< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.BulkRetract.BulkRetract
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/BulkRetract/Endpoint.cs
Line coverage
12%
Covered lines: 4
Uncovered lines: 29
Coverable lines: 33
Total lines: 70
Line coverage: 12.1%
Branch coverage
0%
Covered branches: 0
Total branches: 10
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%
ExecuteAsync()0%110100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/BulkRetract/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.BulkRetract;
 11
 12[PublicAPI]
 113internal class BulkRetract(IWorkflowDefinitionStore store, IWorkflowDefinitionPublisher workflowDefinitionPublisher, IAu
 14    : ElsaEndpoint<Request, Response>
 15{
 16    public override void Configure()
 17    {
 118        Post("/bulk-actions/retract/workflow-definitions/by-definition-ids");
 119        ConfigurePermissions("retract:workflow-definitions");
 120    }
 21
 22    public override async Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken)
 23    {
 024        var authorizationResult = await authorizationService.AuthorizeAsync(User, new NotReadOnlyResource(), Authorizati
 25
 026        if (!authorizationResult.Succeeded)
 27        {
 028            await Send.ForbiddenAsync(cancellationToken);
 029            return null!;
 30        }
 31
 032        var retracted = new List<string>();
 033        var notFound = new List<string>();
 034        var notPublished = new List<string>();
 035        var skipped = new List<string>();
 36
 037        foreach (var definitionId in request.DefinitionIds)
 38        {
 039            var definitions = (await store.FindManyAsync(new WorkflowDefinitionFilter
 040            {
 041                DefinitionId = definitionId,
 042                VersionOptions = VersionOptions.LatestOrPublished
 043            }, cancellationToken: cancellationToken)).ToList();
 44
 045            if (!definitions.Any())
 46            {
 047                notFound.Add(definitionId);
 048                continue;
 49            }
 50
 051            var published = definitions.FirstOrDefault(d => d.IsPublished);
 052            if (published is null)
 53            {
 054                notPublished.Add(definitionId);
 055                continue;
 56            }
 57
 058            if (published.IsReadonly)
 59            {
 060                skipped.Add(definitionId);
 061                continue;
 62            }
 63
 064            await workflowDefinitionPublisher.RetractAsync(published, cancellationToken);
 065            retracted.Add(definitionId);
 066        }
 67
 068        return new Response(retracted, notPublished, notFound, skipped);
 069    }
 70}