diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Migrations/RolesMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Migrations/RolesMigrations.cs index eae78a2ce3a..ab2098f10b5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Migrations/RolesMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Migrations/RolesMigrations.cs @@ -16,13 +16,19 @@ public sealed class RolesMigrations : DataMigration private static readonly string _alternativeAdminRoleName = "SiteOwner"; private readonly SystemRoleOptions _systemRoleOptions; + private readonly ISystemRoleNameProvider _systemRoleNameProvider; + private readonly RoleManager _roleManager; private readonly ILogger _logger; public RolesMigrations( IOptions systemRoleOptions, + ISystemRoleNameProvider systemRoleNameProvider, + RoleManager roleManager, ILogger logger) { _systemRoleOptions = systemRoleOptions.Value; + _systemRoleNameProvider = systemRoleNameProvider; + _roleManager = roleManager; _logger = logger; } @@ -126,6 +132,18 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("MigrateAdminUsersToNewAdm return 1; } + public async Task UpdateFrom1Async() + { + var systemRoles = await _systemRoleNameProvider.GetSystemRolesAsync(); + + foreach (var role in systemRoles) + { + await _roleManager.CreateAsync(new Role { RoleName = role }); + } + + return 2; + } + private static string GenerateNewAdminRoleName(List roles) { var counter = 1; diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Roles/Startup.cs index 236fd1d77e6..6adff2c006c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/Startup.cs @@ -1,7 +1,5 @@ using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -81,7 +79,4 @@ public override void ConfigureServices(IServiceCollection services) services.AddScoped(sp => sp.GetRequiredService()); services.AddScoped(sp => sp.GetRequiredService()); } - - public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) - => app.UseSystemRoles(); } diff --git a/src/OrchardCore.Themes/TheAdmin/Recipes/blank.recipe.json b/src/OrchardCore.Themes/TheAdmin/Recipes/blank.recipe.json index a9dd2357acb..0e9cdc2a774 100644 --- a/src/OrchardCore.Themes/TheAdmin/Recipes/blank.recipe.json +++ b/src/OrchardCore.Themes/TheAdmin/Recipes/blank.recipe.json @@ -65,6 +65,31 @@ "name": "themes", "admin": "TheAdmin", "site": "" + }, + { + "name": "Roles", + "Roles": [ + { + "Name": "Moderator", + "Description": "Grants users the ability to moderate content.", + "Permissions": [] + }, + { + "Name": "Editor", + "Description": "Grants users the ability to edit existing content.", + "Permissions": [] + }, + { + "Name": "Author", + "Description": "Grants users the ability to create content.", + "Permissions": [] + }, + { + "Name": "Contributor", + "Description": "Grants users the ability to contribute content.", + "Permissions": [] + } + ] } ] } diff --git a/src/OrchardCore.Themes/TheAdmin/Recipes/headless.recipe.json b/src/OrchardCore.Themes/TheAdmin/Recipes/headless.recipe.json index f5c3ab88d2d..385c6f45259 100644 --- a/src/OrchardCore.Themes/TheAdmin/Recipes/headless.recipe.json +++ b/src/OrchardCore.Themes/TheAdmin/Recipes/headless.recipe.json @@ -61,6 +61,31 @@ "TheAdmin" ] }, + { + "name": "Roles", + "Roles": [ + { + "Name": "Moderator", + "Description": "Grants users the ability to moderate content.", + "Permissions": [] + }, + { + "Name": "Editor", + "Description": "Grants users the ability to edit existing content.", + "Permissions": [] + }, + { + "Name": "Author", + "Description": "Grants users the ability to create content.", + "Permissions": [] + }, + { + "Name": "Contributor", + "Description": "Grants users the ability to contribute content.", + "Permissions": [] + } + ] + }, { "name": "settings", "HomeRoute": { diff --git a/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json b/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json index e2c9fccd2b7..c8dd925d27e 100644 --- a/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json +++ b/src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json @@ -70,6 +70,31 @@ "admin": "TheAdmin", "site": "TheAgencyTheme" }, + { + "name": "Roles", + "Roles": [ + { + "Name": "Moderator", + "Description": "Grants users the ability to moderate content.", + "Permissions": [] + }, + { + "Name": "Editor", + "Description": "Grants users the ability to edit existing content.", + "Permissions": [] + }, + { + "Name": "Author", + "Description": "Grants users the ability to create content.", + "Permissions": [] + }, + { + "Name": "Contributor", + "Description": "Grants users the ability to contribute content.", + "Permissions": [] + } + ] + }, { "name": "settings", "HomeRoute": { diff --git a/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json b/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json index 1b42aa67a3f..662f6ecd704 100644 --- a/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json +++ b/src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json @@ -84,6 +84,31 @@ "admin": "TheAdmin", "site": "TheBlogTheme" }, + { + "name": "Roles", + "Roles": [ + { + "Name": "Moderator", + "Description": "Grants users the ability to moderate content.", + "Permissions": [] + }, + { + "Name": "Editor", + "Description": "Grants users the ability to edit existing content.", + "Permissions": [] + }, + { + "Name": "Author", + "Description": "Grants users the ability to create content.", + "Permissions": [] + }, + { + "Name": "Contributor", + "Description": "Grants users the ability to contribute content.", + "Permissions": [] + } + ] + }, { "name": "settings", "HomeRoute": { diff --git a/src/OrchardCore.Themes/TheComingSoonTheme/Recipes/comingsoon.recipe.json b/src/OrchardCore.Themes/TheComingSoonTheme/Recipes/comingsoon.recipe.json index 29f7348c055..03a0016101a 100644 --- a/src/OrchardCore.Themes/TheComingSoonTheme/Recipes/comingsoon.recipe.json +++ b/src/OrchardCore.Themes/TheComingSoonTheme/Recipes/comingsoon.recipe.json @@ -67,6 +67,31 @@ "admin": "TheAdmin", "site": "TheComingSoonTheme" }, + { + "name": "Roles", + "Roles": [ + { + "Name": "Moderator", + "Description": "Grants users the ability to moderate content.", + "Permissions": [] + }, + { + "Name": "Editor", + "Description": "Grants users the ability to edit existing content.", + "Permissions": [] + }, + { + "Name": "Author", + "Description": "Grants users the ability to create content.", + "Permissions": [] + }, + { + "Name": "Contributor", + "Description": "Grants users the ability to contribute content.", + "Permissions": [] + } + ] + }, { "name": "settings", "HomeRoute": { diff --git a/src/OrchardCore/OrchardCore.Roles.Core/Extensions/ApplicationBuilderExtensions.cs b/src/OrchardCore/OrchardCore.Roles.Core/Extensions/ApplicationBuilderExtensions.cs deleted file mode 100644 index 9e9fad8772a..00000000000 --- a/src/OrchardCore/OrchardCore.Roles.Core/Extensions/ApplicationBuilderExtensions.cs +++ /dev/null @@ -1,55 +0,0 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.Extensions.DependencyInjection; -using OrchardCore.Security; - -namespace Microsoft.AspNetCore.Builder; - -public static class ApplicationBuilderExtensions -{ - private static readonly IRole[] _systemRoles = - [ - new Role - { - RoleName = "Administrator", - RoleDescription = "A system role that grants all permissions to the assigned users." - }, - new Role - { - RoleName = "Authenticated", - RoleDescription = "A system role representing all authenticated users." - }, - new Role - { - RoleName = "Anonymous", - RoleDescription = "A system role representing all non-authenticated users." - }, - new Role - { - RoleName = "Moderator", - RoleDescription = "Grants users the ability to moderate content." - }, - new Role - { - RoleName = "Author", - RoleDescription = "Grants users the ability to create content." - }, - new Role - { - RoleName = "Contributor", - RoleDescription = "Grants users the ability to contribute content." - } - ]; - - public static IApplicationBuilder UseSystemRoles(this IApplicationBuilder app) - { - using var scope = app.ApplicationServices.CreateAsyncScope(); - var roleManager = scope.ServiceProvider.GetService>(); - - foreach (var role in _systemRoles) - { - roleManager.CreateAsync(role); - } - - return app; - } -}