Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed Jan 13, 2025
1 parent 6117d19 commit da19704
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<IRole> _roleManager;
private readonly ILogger _logger;

public RolesMigrations(
IOptions<SystemRoleOptions> systemRoleOptions,
ISystemRoleNameProvider systemRoleNameProvider,
RoleManager<IRole> roleManager,
ILogger<RolesMigrations> logger)
{
_systemRoleOptions = systemRoleOptions.Value;
_systemRoleNameProvider = systemRoleNameProvider;
_roleManager = roleManager;
_logger = logger;
}

Expand Down Expand Up @@ -126,6 +132,18 @@ await HttpBackgroundJob.ExecuteAfterEndOfRequestAsync("MigrateAdminUsersToNewAdm
return 1;
}

public async Task<int> 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<IRole> roles)
{
var counter = 1;
Expand Down
5 changes: 0 additions & 5 deletions src/OrchardCore.Modules/OrchardCore.Roles/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -81,7 +79,4 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IRoleCreatedEventHandler>(sp => sp.GetRequiredService<RoleUpdater>());
services.AddScoped<IRoleRemovedEventHandler>(sp => sp.GetRequiredService<RoleUpdater>());
}

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
=> app.UseSystemRoles();
}
25 changes: 25 additions & 0 deletions src/OrchardCore.Themes/TheAdmin/Recipes/blank.recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
]
}
]
}
25 changes: 25 additions & 0 deletions src/OrchardCore.Themes/TheAdmin/Recipes/headless.recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 25 additions & 0 deletions src/OrchardCore.Themes/TheAgencyTheme/Recipes/agency.recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
25 changes: 25 additions & 0 deletions src/OrchardCore.Themes/TheBlogTheme/Recipes/blog.recipe.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

This file was deleted.

0 comments on commit da19704

Please sign in to comment.