Conversation
`_get_self_writable_groups()` is subtracted from the user's own groups so the synchronisation never takes those groups away, but it is not subtracted from the groups contributed by the roles. A role implying one of them hands it back on every `res.users.write()`, silently overriding the user's choice. This is visible with `mail.group_mail_notification_type_inbox`, since `notification_type` is stored and computed from that group: a user whose role implies it cannot switch to "Handle by Emails" at all. Picking it removes the group, `set_groups_from_roles` adds it back within the same write, and the compute returns the user to `inbox`. Removing the group by hand only lasts until that user's next write, or until "Update users" is pressed on the role. Subtract the self-writable groups from the roles' groups as well, so a role neither grants nor removes them and the choice stays with the user.
Contributor
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A role implying one of the groups the module itself declares as the user's own
forces that group back on its members, and there is no way to opt out.
_get_self_writable_groups()is subtracted from the user's own groups inset_groups_from_roles, so the synchronisation never takes those groups away.But it is not subtracted from the groups contributed by the roles, so a role
implying one of them adds it again on every
res.users.write().This is plainly visible with
mail.group_mail_notification_type_inbox, becausenotification_typeis a stored field computed from that group. For a user whoserole implies it, switching to Handle by Emails is impossible:
notification_typeremoves the group;set_groups_from_rolesruns within the same write and adds it back;inbox.Saving looks like it worked and the value is back to "Handle in Odoo" on the next
read. Removing the group by hand only lasts until that user's next write, or
until Update users is pressed on the role.
This was found on a production database where five roles implied that group and
twelve users were stuck on inbox notifications.
What this PR changes
The self-writable groups are subtracted from the roles' groups as well, so a role
neither grants nor removes them and the choice stays with the user.
After the fix,
base_user_rolebehaves like core does for any other group thatimplies a self-writable one: core's
UsersImplied.writemay still re-add thegroup through the role's own group, but it does not re-trigger the compute, so
the user's stored preference is preserved. The point of the fix is precisely to
stop the module from issuing the explicit
groups_idwrite that did re-triggerit.
Tests
test_notification_type_not_forcedcovers it: a role implying the inbox group,a user who picks
inbox, thenemail, and an unrelated write afterwards to makesure the synchronisation does not hand the preference back.
Verified on a clean 18.0 database (core + enterprise,
base_user_rolefreshlyinstalled): the new test fails on
18.0with'inbox' != 'email'and the wholesuite passes with the fix, 20 tests, no errors. The existing
test_notification_type_not_resetandtest_notification_type_resetstill pass,so the group is still never taken away from the user, and a user demoted to a
share one is still moved to
email.