< Summary

Information
Class: Elsa.Workflows.Api.Requirements.NotReadOnlyRequirementHandler
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Requirements/NotReadOnlyRequirement.cs
Line coverage
40%
Covered lines: 4
Uncovered lines: 6
Coverable lines: 10
Total lines: 44
Line coverage: 40%
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
.ctor(...)100%11100%
HandleRequirementAsync(...)0%7280%

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
 9public 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 />
 23422    public NotReadOnlyRequirementHandler(
 23423        IOptions<ManagementOptions> managementOptions)
 24    {
 23425        _managementOptions = managementOptions;
 23426    }
 27
 28    /// <inheritdoc />
 29    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, NotReadOnlyRequirement requireme
 30    {
 031        if (_managementOptions.Value.IsReadOnlyMode)
 32        {
 033            context.Fail(new(this, "Workflow edit is not allowed when the read-only mode is enabled."));
 34        }
 35
 036        if (resource.WorkflowDefinition != null && (resource.WorkflowDefinition.IsReadonly || resource.WorkflowDefinitio
 37        {
 038            context.Fail(new(this, "Workflow edit is not allowed for a readonly or system workflow."));
 39        }
 40
 041        context.Succeed(requirement);
 042        return Task.CompletedTask;
 43    }
 44}