-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/OrchardCore.Modules/OrchardCore.Roles/Migrations/SystemRolesMigrations.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.Extensions.Logging; | ||
using OrchardCore.Data.Migration; | ||
using OrchardCore.Security; | ||
|
||
namespace OrchardCore.Roles.Migrations; | ||
|
||
public sealed class SystemRolesMigrations : DataMigration | ||
{ | ||
private readonly ISystemRoleNameProvider _systemRoleNameProvider; | ||
private readonly RoleManager<IRole> _roleManager; | ||
private readonly ILogger _logger; | ||
|
||
public SystemRolesMigrations( | ||
ISystemRoleNameProvider systemRoleNameProvider, | ||
RoleManager<IRole> roleManager, | ||
ILogger<RolesMigrations> logger) | ||
{ | ||
_systemRoleNameProvider = systemRoleNameProvider; | ||
_roleManager = roleManager; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<int> CreateAsync() | ||
{ | ||
var systemRoles = await _systemRoleNameProvider.GetSystemRolesAsync(); | ||
|
||
foreach (var role in systemRoles) | ||
{ | ||
await _roleManager.CreateAsync(new Role { RoleName = role }); | ||
} | ||
|
||
_logger.LogInformation("The system roles have been created successfully."); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters