< Summary

Information
Class: Elsa.Workflows.Api.Requirements.NotReadOnlyResource
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Requirements/NotReadOnlyRequirement.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 1
Coverable lines: 1
Total lines: 44
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_WorkflowDefinition()100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Requirements/NotReadOnlyRequirement.cs

#LineLine coverage
 1using Elsa.Workflows.Management.Entities;
 2using Elsa.Workflows.Management.Options;
 3using JetBrains.Annotations;
 4using Microsoft.AspNetCore.Authorization;
 5using Microsoft.Extensions.Options;
 6
 7namespace Elsa.Workflows.Api.Requirements;
 8
 09public record NotReadOnlyResource(WorkflowDefinition? WorkflowDefinition = default);
 10
 11
 12public record NotReadOnlyRequirement() : IAuthorizationRequirement;
 13
 14
 15/// <inheritdoc />
 16[PublicAPI]
 17public class NotReadOnlyRequirementHandler : AuthorizationHandler<NotReadOnlyRequirement, NotReadOnlyResource>
 18{
 19    private readonly IOptions<ManagementOptions> _managementOptions;
 20
 21    /// <inheritdoc />
 22    public NotReadOnlyRequirementHandler(
 23        IOptions<ManagementOptions> managementOptions)
 24    {
 25        _managementOptions = managementOptions;
 26    }
 27
 28    /// <inheritdoc />
 29    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, NotReadOnlyRequirement requireme
 30    {
 31        if (_managementOptions.Value.IsReadOnlyMode)
 32        {
 33            context.Fail(new(this, "Workflow edit is not allowed when the read-only mode is enabled."));
 34        }
 35
 36        if (resource.WorkflowDefinition != null && (resource.WorkflowDefinition.IsReadonly || resource.WorkflowDefinitio
 37        {
 38            context.Fail(new(this, "Workflow edit is not allowed for a readonly or system workflow."));
 39        }
 40
 41        context.Succeed(requirement);
 42        return Task.CompletedTask;
 43    }
 44}

Methods/Properties

get_WorkflowDefinition()