< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.UpdateReferences.UpdateReferences
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/UpdateReferences/Endpoint.cs
Line coverage
18%
Covered lines: 4
Uncovered lines: 18
Coverable lines: 22
Total lines: 52
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%2040%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/UpdateReferences/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.Contracts;
 7using Elsa.Workflows.Management.Filters;
 8using JetBrains.Annotations;
 9using Microsoft.AspNetCore.Authorization;
 10
 11namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.UpdateReferences;
 12
 13[PublicAPI]
 114internal class UpdateReferences(IWorkflowReferenceUpdater workflowReferenceUpdater, IWorkflowDefinitionStore store, IAut
 15    : ElsaEndpoint<Request, Response>
 16{
 17    public override void Configure()
 18    {
 119        Post("/workflow-definitions/{definitionId}/update-references");
 120        ConfigurePermissions("publish: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.Latest
 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        var result = await workflowReferenceUpdater.UpdateWorkflowReferencesAsync(definition, cancellationToken);
 048        var affectedWorkflows = result.UpdatedWorkflows;
 049        var response = new Response(affectedWorkflows.Select(w => w.Name ?? w.DefinitionId));
 050        await Send.OkAsync(response, cancellationToken);
 051    }
 52}