-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create system roles by default #17341
Merged
Merged
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
bd65eed
Create system roles by default
hishamco 151ad09
Add missing roles
hishamco 6117d19
Remove roles from *.recipe.json
hishamco da19704
Address feedback
hishamco 718d098
Merge branch 'main' into hishamco/system-roles
hishamco a79ade2
Create a separate data migration
hishamco 5e21655
Remove system roles from migrations.recipe.json
hishamco e5e0c0d
Address feedback
hishamco 915a554
Merge branch 'main' into hishamco/system-roles
hishamco 5b70ef2
Remove roles from pages.recipe.json
hishamco 784e912
Introduce ISystemRoleProvider
hishamco 7ee0c37
Remove warnings
hishamco 9d38a6c
Merge branch 'main' into hishamco/system-roles
hishamco 56ffeb3
Apply suggestions from code review
hishamco cb0fd77
localize the description
hishamco 0a49bae
Merge branch 'main' into hishamco/system-roles
hishamco 7a2da40
Remove obsolete from DefaultSystemRoleNameProvider
hishamco b97848f
Don't depend on role position
hishamco 9026f46
Add GetAdminRoleAsync() to ISystemRoleProvider
hishamco fa7775a
Merge branch 'main' into hishamco/system-roles
hishamco 48a3719
Remove ISystemRoleNameProvider injection
hishamco 3f104ab
Add more unit tests
hishamco 674c862
Fix the build
hishamco 748e6d8
localizer -> stringLocalizer
hishamco 313651e
Obsolete SystemRoleNameProviderExtensions
hishamco d2245e3
Address feedback
hishamco 2470fb7
Fix warnings
hishamco 7b7ba19
Apply suggestions from code review
hishamco b3c15a6
Fix the build
hishamco 26177f3
Remove unnecessary local field
hishamco fd7e657
Remove extra cast
hishamco ea580d0
cleanup for approval
MikeAlhayek 1791300
Fix tests
MikeAlhayek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
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,40 @@ | ||
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 ISystemRoleProvider _systemRoleProvider; | ||
private readonly RoleManager<IRole> _roleManager; | ||
private readonly ILogger _logger; | ||
|
||
public SystemRolesMigrations( | ||
ISystemRoleProvider systemRoleProvider, | ||
RoleManager<IRole> roleManager, | ||
ILogger<RolesMigrations> logger) | ||
{ | ||
_systemRoleProvider = systemRoleProvider; | ||
_roleManager = roleManager; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<int> CreateAsync() | ||
{ | ||
var systemRoles = _systemRoleProvider.GetSystemRoles(); | ||
|
||
foreach (var systemRole in systemRoles) | ||
{ | ||
if (!await _roleManager.RoleExistsAsync(systemRole.RoleName)) | ||
{ | ||
await _roleManager.CreateAsync(systemRole); | ||
} | ||
} | ||
|
||
_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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SaaS recipe still has these.
pages.recipe.json
too but I'm not sure how that's used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too :) but seems used the module for test project to test Assembly attributes if I recall