< 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: 78
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.Platform.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[ManifestFeatureCategory("Identity")]
 15[ManifestFeatureCategory("Security")]
 16[ShellFeature(
 17    DisplayName = "Default Admin User Initialization",
 18    Description = "Initializes a default admin user from configuration if provided",
 19    DependsOn = [typeof(IdentityFeature)])]
 20[UsedImplicitly]
 21public class DefaultAdminUserFeature : IShellFeature
 22{
 23    /// <summary>
 24    /// Gets or sets the admin user name. Must be explicitly configured to enable user bootstrap.
 25    /// </summary>
 26    [ManifestSetting(
 27        DisplayName = "Admin User Name",
 28        Description = "User name for the default admin account to bootstrap.",
 29        Category = "Bootstrap",
 30        RestartRequired = true)]
 031    public string AdminUserName { get; set; } = "";
 32
 33    /// <summary>
 34    /// Gets or sets the admin user password. Must be explicitly configured to enable user bootstrap.
 35    /// </summary>
 36    [ManifestSetting(
 37        DisplayName = "Admin Password",
 38        Description = "Password for the default admin account to bootstrap.",
 39        Category = "Bootstrap",
 40        Secret = true,
 41        Sensitive = true,
 42        RestartRequired = true)]
 043    public string AdminPassword { get; set; } = "";
 44
 45    /// <summary>
 46    /// Gets or sets the admin role name.
 47    /// </summary>
 48    [ManifestSetting(
 49        DisplayName = "Admin Role Name",
 50        Description = "Role assigned to the default admin account.",
 51        Category = "Bootstrap",
 52        DefaultValue = "admin",
 53        RestartRequired = true)]
 054    public string AdminRoleName { get; set; } = "admin";
 55
 56    /// <summary>
 57    /// Gets or sets the admin role permissions.
 58    /// </summary>
 59    [ManifestSetting(
 60        DisplayName = "Admin Role Permissions",
 61        Description = "Permissions assigned to the default admin role.",
 62        Category = "Bootstrap",
 63        DefaultValue = "*",
 64        RestartRequired = true)]
 065    public ICollection<string> AdminRolePermissions { get; set; } = ["*"];
 66
 67    public void ConfigureServices(IServiceCollection services)
 68    {
 069        services.Configure<DefaultAdminUserOptions>(options =>
 070        {
 071            options.AdminUserName = AdminUserName;
 072            options.AdminPassword = AdminPassword;
 073            options.AdminRoleName = AdminRoleName;
 074            options.AdminRolePermissions = AdminRolePermissions;
 075        });
 076        services.AddBackgroundTask<AdminUserInitializer>();
 077    }
 78}