< Summary

Information
Class: Elsa.Identity.Endpoints.Roles.Create.Create
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/Endpoints/Roles/Create/Endpoint.cs
Line coverage
53%
Covered lines: 16
Uncovered lines: 14
Coverable lines: 30
Total lines: 65
Line coverage: 53.3%
Branch coverage
0%
Covered branches: 0
Total branches: 4
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.Identity/Endpoints/Roles/Create/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Identity.Contracts;
 3using Elsa.Identity.Entities;
 4using Elsa.Workflows;
 5using Humanizer;
 6using JetBrains.Annotations;
 7
 8namespace Elsa.Identity.Endpoints.Roles.Create;
 9
 10/// <summary>
 11/// An endpoint that creates a new role.
 12/// </summary>
 13[PublicAPI]
 14internal class Create : ElsaEndpoint<Request, Response>
 15{
 16    private readonly IIdentityGenerator _identityGenerator;
 17    private readonly ISecretGenerator _secretGenerator;
 18    private readonly ISecretHasher _secretHasher;
 19    private readonly IUserStore _userStore;
 20    private readonly IRoleStore _roleStore;
 21
 122    public Create(
 123        IIdentityGenerator identityGenerator,
 124        ISecretGenerator secretGenerator,
 125        ISecretHasher secretHasher,
 126        IUserStore userStore,
 127        IRoleStore roleStore)
 28    {
 129        _identityGenerator = identityGenerator;
 130        _secretGenerator = secretGenerator;
 131        _secretHasher = secretHasher;
 132        _userStore = userStore;
 133        _roleStore = roleStore;
 134    }
 35
 36    /// <inheritdoc />
 37    public override void Configure()
 38    {
 139        Post("/identity/roles");
 140        ConfigurePermissions("create:role");
 141        Policies(IdentityPolicyNames.SecurityRoot);
 142    }
 43
 44    /// <inheritdoc />
 45    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 46    {
 047        var id = request.Id ?? request.Name.Kebaberize();
 48
 049        var role = new Role
 050        {
 051            Id = id,
 052            Name = request.Name,
 053            Permissions = request.Permissions ?? new List<string>()
 054        };
 55
 056        await _roleStore.SaveAsync(role, cancellationToken);
 57
 058        var response = new Response(
 059            id,
 060            role.Name,
 061            role.Permissions);
 62
 063        await Send.OkAsync(response, cancellationToken);
 064    }
 65}