diff --git a/src/security/src/AXOpen.Security/Services/ServicesConfiguration.cs b/src/security/src/AXOpen.Security/Services/ServicesConfiguration.cs index da0f4dc6b..93a8ec8f8 100644 --- a/src/security/src/AXOpen.Security/Services/ServicesConfiguration.cs +++ b/src/security/src/AXOpen.Security/Services/ServicesConfiguration.cs @@ -17,7 +17,7 @@ public static class ServicesConfiguration { public static void ConfigureAxBlazorSecurity(this IServiceCollection services, (IRepository userRepo, IRepository groupRepo) repos, - List? roles = null) + List? roles = null, bool addAllRolesToAdminGroup = false) { services.AddTransient, UserStore>(); services.AddTransient, RoleStore>(); @@ -36,9 +36,20 @@ public static void ConfigureAxBlazorSecurity(this IServiceCollection services, RoleGroupManager roleGroupManager = new RoleGroupManager(repos.groupRepo); - if (roles != null) + if (roles != null ) { roleGroupManager.CreateRoles(roles); + if (addAllRolesToAdminGroup) + { + List currentAdminRoles = roleGroupManager.GetRolesFromGroup("AdminGroup").Where(c => ! c.Equals("Administrator")).ToList(); + List? requiredAdminRoles = roles.Select(c => c.Name).ToList(); + List? adminRolesToAdd = requiredAdminRoles?.Where(p => currentAdminRoles.All(p2 => p2 != p)).ToList(); + List? adminRolesToRemove = currentAdminRoles?.Where(p => requiredAdminRoles.All(p2 => p2 != p)).ToList(); + + roleGroupManager.AddRolesToGroup("AdminGroup", adminRolesToAdd); + roleGroupManager.RemoveRolesFromGroup("AdminGroup", adminRolesToRemove); + + } } services.AddScoped(provider => new RepositoryService(repos.userRepo, roleGroupManager));