< Summary

Information
Class: Elsa.Server.Web.Activities.AuthorizeFlow
Assembly: Elsa.Server.Web
File(s): /home/runner/work/elsa-core/elsa-core/src/apps/Elsa.Server.Web/Activities/AuthorizeFlow.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 16
Coverable lines: 16
Total lines: 49
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ExecuteAsync(...)0%620%
OnResumeAsync()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/apps/Elsa.Server.Web/Activities/AuthorizeFlow.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows;
 3using Elsa.Workflows.Activities.Flowchart.Attributes;
 4using Elsa.Workflows.Attributes;
 5
 6namespace Elsa.Server.Web.Activities;
 7
 8[Activity("Elsa", "Authorization", "Authorizes a flow based on the configured policies.")]
 9[FlowNode("Authorized", "Unauthorized", "Error")]
 10public class AuthorizeFlow : Activity<string>
 11{
 12    protected override ValueTask ExecuteAsync(ActivityExecutionContext context)
 13    {
 014        var httpContext = context.GetRequiredService<IHttpContextAccessor>().HttpContext;
 15
 016        if (httpContext == null)
 017            throw new InvalidOperationException("HttpContext is not available. Ensure that the activity is executed with
 18
 019        var bookmark = context.CreateBookmark(new AuthorizeStimulus(), OnResumeAsync);
 020        var redirectUrl = context.ExpressionExecutionContext.GenerateBookmarkTriggerUrl(bookmark.Id);
 21
 022        Result.Set(context, redirectUrl);
 023        return ValueTask.CompletedTask;
 24    }
 25
 26    private async ValueTask OnResumeAsync(ActivityExecutionContext context)
 27    {
 028        if (!context.TryGetWorkflowInput<string>("Answer", out var response))
 29        {
 030            await context.CompleteActivityWithOutcomesAsync("Unauthorized");
 031            return;
 32        }
 33
 34        switch (response)
 35        {
 36            case "Authorized":
 037                await context.CompleteActivityWithOutcomesAsync("Authorized");
 038                return;
 39            case "Error":
 040                await context.CompleteActivityWithOutcomesAsync("Error");
 041                return;
 42            default:
 043                await context.CompleteActivityWithOutcomesAsync("Unauthorized");
 44                break;
 45        }
 046    }
 47}
 48
 49public record AuthorizeStimulus;