fix(usergroups): clear cached user groups on pre hooks#45036
fix(usergroups): clear cached user groups on pre hooks#45036iLinaza wants to merge 2 commits intonextcloud:masterfrom
Conversation
Signed-off-by: iLinaza <[email protected]>
|
I am not sure which side effects this would have. Scary change ;) Would it not be better to emit additional Events in user_saml? |
|
In my case, am clearing the cache in the pre event, using reflectivity from a custom App, and it is working fine, but I don't know if it can have consequences in other Apps that we don't use. Clearing the cache of groups to which users belong must be the task immediately before or after the user is added to a group. I understand that, if we could ensure that, doing it in the pre-hook is the last thing to be executed it should be working fine, but I don't think priority can be added to hook subscriptions, as it is possible with Events. Otherwise, as you say, a new event or Hook could be added, but in the long run the same problem (execution order) could occur if more applications use that event? Alternatively, we could use the already existing event, UserAddedEvent, and add the subscription to clear the cache with the highest possible priority value, instead of using the post- hooks. |
|
@blizzz, would something like hrenard@0aefd68 be safer ? |
|
For the record, the underlying code has changed slightly in master.
I think effectively it is the same. ccing @come-nc for another opinion on this matter. |
|
Hello, I think the change makes sense. But it should get migrated to events anyway, so might as well use the priority solution instead and migrate to events right away. It also avoids clearing the cache if the deletion fails. |
|
This PR fixes a bug in Nextcloud that I was fighting with for years. I am using the Social Login app for OAuth authentication. It is able to create Nextcloud users if they do not yet exist and sync group memberships. The newly created users are correctly added to the Nextcloud groups returned by the OAuth provider. The problem is: They never get access to the group's shares which they obviously should. Simply no entries are created in For a long time I thought this was a bug in the Social Login app, but after debugging this issue for hours, I found this to be caused by the incorrect caching in
The cache needs to be cleared before the user is added to a group so that Why isn't this issue happening when adding a user to a group through the user management UI? Simply because step 3 doesn't happen in that case and therefore no empty group membership is cached before the user is added to the group, the cache is still empty. So the issue is then only hidden, but the order of caching and clearing the cache is still incorrect. This PR contains a simple but important change. To me it's also not a very scary one. We're just changing when the cache is cleared, worst case the cache might to be cleared too eagerly, at least we're not acting upon an outdated cache. I'd be very happy if this gets merged. I was about to create a PR with a fix myself before I found this one. I am happy to help getting this PR over the finish line if @iLinaza is currently not available to resolve the conflicts. |
…hooks Signed-off-by: Côme Chilliet <[email protected]>
come-nc
left a comment
There was a problem hiding this comment.
Alright, let’s merge this as a quickfix, and these hooks can be moved to events later.
I solved conflicts with master.
Summary
Groups Manager stores the cache of which groups the users belong to. This can be inconsistent at certain times as it is cleared late (in post hooks).
When a user is added to a group the following steps are taken (in OC\Group\Group, addUser method):
The cache is cleared in the postAddUser hook, in the Manager. When someone performs operations on the UserAddedEvent event and is checking which groups the user belongs to, the Manager may be returning invalid data since the cache may be in an inconsistent state. The user has already been added to the group but the cache is cleared later, in the postAddUser hook, and the manager returns outdated group list.
Before the cache is cleared, the file_sharing app is doing the sharing of folders to the newly added user (in OCA\Files_Sharing\Listener\UserAddedToGroupListener), in the UserAddedEvent event. But, at this point, when the user is created by SAML, the cache is in a incosistent state because it has not been cleared yet and is being retrieved from cache. It will be cleared later, in the postAddUser hook.
Checklist