-
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
Add IsSystem property to IRole interface to allow identifing the system roles easily. #11920
Comments
I was thinking before to add the roles in a class as you mentioned, but with extra thing. Localize them will be extra plus |
I might work on roles list with minimal solution to support localize them. Then you can do the refactoring |
@hishamco localizing the roles may be a good idea too. I like to know which approach (of the 2 above or perhaps other) would be acceptable by the OC team on cleaning the code? |
I don't think there's an issue with the extension method, but let me dig into your changes, and how many places that we have redundant code that we can simplify and refactor |
@sebastienros @hishamco @Skrypt here is maybe even a better way to do this which will give us much more flexibility and would allow uses to not use unwanted default roles using a startup recipe. Currently, in the roles recipe, we can add role, but you can't exclude recipe roles from being created or even remove permission from the default roles "at the initial setup". For example, you can't say create a tenant without The idea is to add a type for each role, then get roles by type. For the sake of the original enhancement, the "Anonymous" and "Authenticated" roles will have To do that, we'll add
In the
This approach will go a long way because now we don't have to force the user to even use the default roles. You would define which roles you want to use by default in the recipe. Using such approach allows us to change
to something like this
It would be even nicer if we convert Now the
I think this would be considered a breaking change since all setup recipes will need to also include the default roles. But it should be acceptable change since we can just add the roles to the existing recipes. and we can place instruction for users to upgrade their setup recipes to include default roles. |
Is your feature request related to a problem? Please describe.
In many instances in OrchardCore's code, we repetitively use the following code
These two roles are system roles; IMO, both should be grouped somehow.
Describe the solution you'd like
First it may be a good idea to add the following class to reduce the use of these terms all over the place.
I can think of two approaches to clean up the code
Option 1: Flagging the System Role
I think this may be a better option even if it require few changes. But the idea is to add
bool IsSystem { get; }
property to the IRole interface Then,IsSystem
flag to true when adding these 2 roles. Perhaps we should also addIsSystem
flag to PermissionStereotype also since that is used to create the role internally via RoleUpdaterotherwise, we would have to add a check if the new role is system based or not
bool IsSystem
property in Role like thisbool includeSystemRoles = true
parameter to allow us to easily remove the system roles.Option 2: Use extensions methods
A less invasive options may be create an extension for the
IRoleService
. I feel approach is a patch but may be more acceptable since the change would be minimal. The idea would be to update the existing RoleServiceExtensions by changing it to something like thisThe
RoleHelper
method would come in handy when refactoring code like the one hereThere could be better ways to do this. Idea?
If this is something we are willing to adopt, suggest the better approach and I'll create a PR for this.
The text was updated successfully, but these errors were encountered: