< Summary

Information
Class: Elsa.Identity.ShellFeatures.DefaultAdminUserFeature
Assembly: Elsa.Identity
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/ShellFeatures/DefaultAdminUserFeature.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 13
Coverable lines: 13
Total lines: 76
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_AdminUserName()100%210%
get_AdminPassword()100%210%
get_AdminRoleName()100%210%
get_AdminRolePermissions()100%210%
ConfigureServices(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Identity/ShellFeatures/DefaultAdminUserFeature.cs

#LineLine coverage
 1using CShells.Features;
 2using Elsa.Extensions;
 3using Elsa.Identity.HostedServices;
 4using Elsa.Identity.Options;
 5using Elsa.PackageManifest.Generator.Hints;
 6using JetBrains.Annotations;
 7using Microsoft.Extensions.DependencyInjection;
 8
 9namespace Elsa.Identity.ShellFeatures;
 10
 11/// <summary>
 12/// Feature that initializes an admin user from configuration if provided.
 13/// </summary>
 14[ShellFeature(
 15    DisplayName = "Default Admin User Initialization",
 16    Description = "Initializes a default admin user from configuration if provided",
 17    DependsOn = ["Identity"])]
 18[UsedImplicitly]
 19public class DefaultAdminUserFeature : IShellFeature
 20{
 21    /// <summary>
 22    /// Gets or sets the admin user name. Must be explicitly configured to enable user bootstrap.
 23    /// </summary>
 24    [ManifestSetting(
 25        DisplayName = "Admin User Name",
 26        Description = "User name for the default admin account to bootstrap.",
 27        Category = "Bootstrap",
 28        RestartRequired = true)]
 029    public string AdminUserName { get; set; } = "";
 30
 31    /// <summary>
 32    /// Gets or sets the admin user password. Must be explicitly configured to enable user bootstrap.
 33    /// </summary>
 34    [ManifestSetting(
 35        DisplayName = "Admin Password",
 36        Description = "Password for the default admin account to bootstrap.",
 37        Category = "Bootstrap",
 38        Secret = true,
 39        Sensitive = true,
 40        RestartRequired = true)]
 041    public string AdminPassword { get; set; } = "";
 42
 43    /// <summary>
 44    /// Gets or sets the admin role name.
 45    /// </summary>
 46    [ManifestSetting(
 47        DisplayName = "Admin Role Name",
 48        Description = "Role assigned to the default admin account.",
 49        Category = "Bootstrap",
 50        DefaultValue = "admin",
 51        RestartRequired = true)]
 052    public string AdminRoleName { get; set; } = "admin";
 53
 54    /// <summary>
 55    /// Gets or sets the admin role permissions.
 56    /// </summary>
 57    [ManifestSetting(
 58        DisplayName = "Admin Role Permissions",
 59        Description = "Permissions assigned to the default admin role.",
 60        Category = "Bootstrap",
 61        DefaultValue = "*",
 62        RestartRequired = true)]
 063    public ICollection<string> AdminRolePermissions { get; set; } = ["*"];
 64
 65    public void ConfigureServices(IServiceCollection services)
 66    {
 067        services.Configure<DefaultAdminUserOptions>(options =>
 068        {
 069            options.AdminUserName = AdminUserName;
 070            options.AdminPassword = AdminPassword;
 071            options.AdminRoleName = AdminRoleName;
 072            options.AdminRolePermissions = AdminRolePermissions;
 073        });
 074        services.AddBackgroundTask<AdminUserInitializer>();
 075    }
 76}