OCA / server-backend

GNU Affero General Public License v3.0
96 stars 263 forks source link

base_user_role resets Notification User preference #293

Open Marrieta99 opened 3 months ago

Marrieta99 commented 3 months ago

Module

base_user_role

Describe the bug

When a user's roles are altered,

To Reproduce

Affected versions: V17 at least, have not tried it in other versions

Steps to reproduce the behavior:

  1. A user changes their notification_type selection from 'Handle by Emails' (default) to 'Handle in Odoo'
  2. The user's roles list is modified (A role is added or removed)
  3. The user's notification_type has been set back to 'Handle by Emails'

Expected behavior User's notification handling preferences shouldn't change, regardless of their roles

Additional context Found this bug in my Odoo.sh instance. Version is 17.0+e (Enterprise Edition) The bug was found in my productive (main) branch, and successfully replicated in a fresh dev database with only the base_user_role module installed

COSTLAND commented 1 month ago

Additional Information

I've been able to reproduce this bug in Odoo v16 Enterprise Edition as well. After further investigation, I've identified some additional details about the issue:

Root Cause

The issue appears to be linked with the recalculation of the User Types / Internal User group. When the last role containing the User Types / Internal User group is removed (even temporarily without saving), the user type is reset. This reset causes the user's notification type to revert to its default value (email).

Explanation

This behavior is consistent with normal Odoo operations regarding user types. When all roles containing the Internal User group are removed, even momentarily, Odoo recalculates the user type, which triggers a reset of user preferences, including the notification type.

Workaround

To prevent this reset from occurring, it's crucial to always maintain at least one role that contains the User Types / Internal User group for each user. Here's a step-by-step process to safely modify roles without triggering the reset:

  1. When replacing Role A with Role B (assuming both contain the Internal User group): a. First, add Role B to the user b. Save the changes c. Then, remove Role A

This approach ensures that the Internal User group is never completely removed during the process, avoiding the recalculation of the user type.

Alternative Solution

Create a separate user group dedicated to containing only the User Types / Internal User group. Always keep this group assigned to the user. This allows you to freely add, remove, or replace other roles without forcing a recalculation of the user type, thus avoiding the reset of user communication preferences.