-
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
Roles Updating and History #13040
Roles Updating and History #13040
Conversation
Nothing tried yet so not fully sure of the following, and as a reminder of my current analysis.
Just for info about other things I saw and other thoughts I had previously.
But as said in the first section, we may not need all of this if we re-use the Feature Installing event and a new Role Creation event, without anything on shell activation and without any history. Oh yes forgot to talk about the case where this is the
|
The only thing is when we disable and re-enable the Let me know if we really need this. If so maybe an history but with only feature Ids for which a role was already auto assigned, and by still only using the event handlers, still nothing on shell activation and in the controller. |
@jtkech IMHO, I think we should to keep track of any permissions that are explicitly remove or added to a role. If an admin included/excluded a permission we should not revert their changes. I also think, the permission provider should be evaluated when a feature is installed and also when it is enabled. This way when any feature is enabled we assign any permission provided by the feature that were not explicitly removed by an admin. Keep in mind, there maybe more permission provided by a feature after the initial installation. At the same time we should honor any specific changes an admin included/excluded. Question for clarification, beside the bottom code change in the controller, what other issues are you trying to solve?
|
This is the case here if you analyze my comments.
Idem, this is the case here.
Yes I thought about this use case, would be one use case if we want to support this.
This is the case here.
You may need to refresh the
At least the current 2 breaking issues mentioned in my comments, for other improvements (if possible) as not running the logic on each shell activation, not use the role document directly, remove the useless code in the controller, reduce the role document that may be in a shared cache, reffer to my comments. For all the above points, please read my previous comments and try it for confirmation. For me there are only 2 cases where we would need an history, the one you mentioned when we upgrade a feature that is already installed and that provides more permissions. Then you didn't answer to the question if we really need to support the case when the At least here we fix 2 issues and we did a lot of cleanups, then if we want to support one of the 2 above cases, as described in my previous comments I can re-use a kind of history but still in a simpler way. |
For infos 2 things I'm thinking about and that I already described in previous comments.
So just to say that anyway many things needed to be cleaned up. Just saw your above edited comment.
I don't use anymore this code, here the controller is as it was before we move role creation in recipes. |
@jtkech Let me know when you are done with all you changes and I'll test it out. |
You can already test it knowing that here the Controller and RoleUpdater are as they were before we moved roles creations in recipes, the only thing I added is the new Role Created event. And that for now the 2 below points are not supported, because we would need to re-use the History.
Hmm what we now support here is when we create a new role (having a default role name) from the UI, it is immediately populated with the auto-assigned permissions by the new Role Created event. |
@jtkech if this is ready you may want to remove the I just tested it and both #13035 and #13024 and I can't reproduce the issues. So the changes fixed them.
PR #12420 should be merged once we get the failing tests to work. So I think we should account for it.
I am not sure I understand here. Anything specific you want me to test out? |
About Hmm but if you really want to support this use case, we could wait a little before merging, I will think about this use case and will let you know. About the 2nd point I was referring to your comment
Here I understood if the code implementation change => maybe more default permissions. If so, I will also think about this other use case and will let you know. |
Okay, as you moved some default services to core projects in #12420, maybe we could think about the same for all or part of the Hmm, but we would still need to use the Roles Document Manager directly to update the underlying roles even if they are not actives, but which is already the case in the current implementation, but no more the case at the moment in this PR, will see. I could start on this when #12420 will get merged, hmm but if it takes some time maybe better to first also merge this PR, will see. |
Okay I tried to move So I created a new feature You can try it to see if all your needs are fit, the only remaining use case is when the code of a feature is upgraded AND provides more default permissions than before. Edited: Hmm, the above would mean that this feature upgrade "installs" something new, so the recommendation could be to add to this feature a dependency on a new feature that will be auto Installed and that at least (can be used for other things) provides these new permissions. 2 quick questions, too lazy to verify atm.
|
The issue with the disabled button is fixed in PR #12950 I'll look at the other stuff tomorrow |
No there isn't. The only place this is mentioned. I think the only place this is mentioned is in the PR itself. I think we should document this in 1.6 release notes. Also, we may want to add a note on https://docs.orchardcore.net/en/latest/docs/reference/modules/Recipes/#roles-step . Can you please make this part of this PR?
Glad to see you using
If we you go the
If you add them here, be sure to also remove them from |
Okay for Do you want to test it out before merging ? In the meantime I will add something in the doc. |
I'll test it now. |
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.
Small feedback while I am waiting on the project to build
Co-authored-by: Mike Alhayek <[email protected]>
Co-authored-by: Mike Alhayek <[email protected]>
@jtkech for some I can't get your branch to run locally. I have to leave here soon and do not want to block your PR. A code review seems to be good. If you tested it and feel good about it, feel free to merge it. I can do more testing once it's merged. |
Hmm, I think I missed one use case.
Would need to know the roles that didn't saw the installation of a given feature, so that enabling again this feature would be like a pseudo installation for these roles. I will think about it. But still worth to try the other use cases, and if they work maybe first merge this PR, then I will work on the above case, but only if we really need to support it. |
Okay just saw your last comment, no problem I will merge soon this PR to fix the current issues. About the last use case, I think I found a solution that would be consistent with existing tenants, so I'm waiting one day more before merging, will see tomorrow. |
Okay I implemented the last use case. We persit the missing features per role, those that are installed but not currently enabled while creating a role, and only those defining permission providers (a few ones). When re-enabling such a feature we update the roles that missed it on creation and update the cache. When removing a Role we remove the missing features for this role. Let me know if you want to try it. |
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.
I was having hard time building the project for some reason. I think if you feel good about this PR, you should merge it as the code looks good. I'll test it more once it's in the main branch.
@@ -67,10 +67,17 @@ public async Task<IdentityResult> CreateAsync(IRole role, CancellationToken canc | |||
throw new ArgumentNullException(nameof(role)); | |||
} | |||
|
|||
var roleToCreate = (Role)role; |
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.
Maybe here we should use is
directive
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.
Didn't want to change the behavior but will check
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.
Just used the same pattern as used below for the existing IRoleRemovedEventHandler
.
var roleToRemove = (Role)role;
/// </summary> | ||
public Dictionary<string, List<string>> PermissionGroups { get; set; } = new(StringComparer.OrdinalIgnoreCase); | ||
public List<Role> Roles { get; set; } = new(); | ||
public Dictionary<string, List<string>> MissingFeaturesByRole { get; set; } = new(); |
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.
It seems weird to track missing items instead of what we know.
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.
See my last comment for the logic where we only use feature / role events, when creating a role we enlist the missing features (installed but not enabled) and only those defining providers, so that when re-enabling such a feature we can lazily update roles that missed it on creation.
Not the only reason but for example doing the opposite would be harder to manage existing tenants, would need a "migration" path to init the history for all existing roles assuming that all installed features was already used, so only using the events would not be sufficient.
Also doing this way, on startup nothing is done on existing tenants until a new role is created, also on a fresh setup this history is just empty, only populated when we disable a feature that provide perms for a given default role that doesn't exist yet, and then create this default role.
In summary when only using events, we need these missing features while creating a role, before it was not needed as default roles was auto created by features.
That's why I first kept the feature Installed event as before, and then because we now can create a default role later on, we need these missing features (installed but no more enabled) to lazily "install" them for this role when they are re-activated.
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.
That's said I may have done something wrong as there are so many scenarios I tried to keep while still fixing the 2 current issues. YOLO ;)
@jtkech Can you summarize the changes of this PR? |
This PR is only related to Roles and their Permissions, not about adding RoleNames to user.
This is the right behavior relying on aspnetcore security services, as I have tried this is now the case unless for the "Administrator" user role because of another issue #13086. But working with @MikeAlhayek he said to me that he has an existing installation where User.RoleNames are not normalized (not all uppercases), and it seems to be the case for you. So maybe having normalized User.RoleNames (which is the right behavior) has been introduced at some point, we are investigating. |
@jtkech I thought maybe an issue with the normalizer, but that one uses ToUpperCaseInvarient() so it should not change. I tried to locate any changes around the UserDisplayDriver, UserStore and the ILookupNormalizer in recent changes but I do not see what could have changed. Maybe something changed in the invariant culture in YesSql/sterilizer or in OC that I am not aware of? |
@mariojsnunes Fixed by #13104 |
Awesome, thanks!! |
Just started, not ready to be reviewed and merged, planned to fix #13024 and fix #13035
So to fix the dynamic permissions in the Controller and on starup to take into account the existing tenants that don't have yet a permissions history.
Then maybe other things to do, there are many scenarios, need to be sure I well understand what should be done, I have ideas but need more time to coordinate them, here some first thoughts.
Not sure it"s good to assume that
RoleStore
rely onIDocumentManager
, maybe too late.I would like, if possible, to prevent from evaluating the permission providers on each shell activation, by only using
IFeatureEventHandler
and maybe a newIRoleEventHandler
, currently onlyIRoleRemovedEventHandler
exists.Some
Xxxed
feature events are triggered in a deferred task, so a feature handler can be triggered when the feature that registers it is enabled. So could be used whenRoles
itself is enabled again.When we delete a role, should we remove its related history, currently not the case but I assume yes.
When we lazily create a role, e.g. through the Admin UI, if it is a default role for some features, should we hydrate its permissions lazily, I assume yes, currently this is the case but only on the next startup.
Hmm, maybe we only need to add to the history the permissions that we remove (to not be auto added again) but not the others as we do on startup.
RoleStep: Hmm a little annoying, it specifies permissions (can be empty) that also rely on features activation, maybe the step should merge (not replace) permissions, at least when in a setup recipe, or maybe a new step for role creation only and if it already exists don't replace/clear its permissions.
@hyzx86 @gvkries I will let you know when it will be ready to be tested.
@MikeAlhayek I will let you check if it still fits your needs.