diff options
| author | Nans Lefebvre <len@odoo.com> | 2019-07-29 12:49:55 +0000 |
|---|---|---|
| committer | fw-bot <otis@odoo.com> | 2019-09-19 12:49:11 +0000 |
| commit | 7571b086bdfc58df90f204869d9bbfb138605efb (patch) | |
| tree | cca830234d2820906bc20816ef644a61db5d6319 /odoo/addons/base/models/res_users.py | |
| parent | ce7090001d104fb43afacfd64e48d182b0ff8761 (diff) | |
[FIX] base: fix portal rights update
Commit c3717f3018 added a (5, 0, 0) command when modifying groups_id of any
non-internal user, to avoid the situation where the various implications would
end up giving the portal user group_user rights.
This risk is avoided by commit f206714af08, which added a constraint
check_one_user_type, which would raise in that specific case.
The last missing piece was 9badedcd98f; when groups are added through settings,
they are added through the implied_groups of the group model.
The (5,) command has the unfortunate side-effect to remove the portal group
from a user if a write is triggered programmatically.
If that happens, then the 'signing up' process end-destination is a 500 error.
Now we simplify the logic that keeping the same behaviour for implied_ids for
internal (group_user) and non-internal users.
We keep the (5,) command in one case: if a user is demoted to portal or public,
he may have groups should be reserved to internal users, but that do not imply
group_user (which would raise).
To avoid that, we remove all its groups, since there is no clear distinction
between technical display groups and actual privilege-granting groups.
opw 2041606
closes odoo/odoo#37144
X-original-commit: 29723e351d5dc5e5ea055c80da86f4e871909de9
Signed-off-by: Nans Lefebvre (len) <len@odoo.com>
Diffstat (limited to 'odoo/addons/base/models/res_users.py')
| -rw-r--r-- | odoo/addons/base/models/res_users.py | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/odoo/addons/base/models/res_users.py b/odoo/addons/base/models/res_users.py index 002693ee781..cad105b0ea7 100644 --- a/odoo/addons/base/models/res_users.py +++ b/odoo/addons/base/models/res_users.py @@ -1000,24 +1000,20 @@ class UsersImplied(models.Model): if 'groups_id' in values: # complete 'groups_id' with implied groups user = self.new(values) - group_public = self.env.ref('base.group_public', raise_if_not_found=False) - group_portal = self.env.ref('base.group_portal', raise_if_not_found=False) - if group_public and group_public in user.groups_id: - gs = self.env.ref('base.group_public') | self.env.ref('base.group_public').trans_implied_ids - elif group_portal and group_portal in user.groups_id: - gs = self.env.ref('base.group_portal') | self.env.ref('base.group_portal').trans_implied_ids - else: - gs = user.groups_id | user.groups_id.mapped('trans_implied_ids') + gs = user.groups_id | user.groups_id.mapped('trans_implied_ids') values['groups_id'] = type(self).groups_id.convert_to_write(gs, user.groups_id) return super(UsersImplied, self).create(vals_list) @api.multi def write(self, values): + users_before = self.filtered(lambda u: u.has_group('base.group_user')) res = super(UsersImplied, self).write(values) if values.get('groups_id'): # add implied groups for all users for user in self.with_context({}): - if not user.has_group('base.group_user'): + if not user.has_group('base.group_user') and user in users_before: + # if we demoted a user, we strip him of all its previous privileges + # (but we should not do it if we are simply adding a technical group to a portal user) vals = {'groups_id': [(5, 0, 0)] + values['groups_id']} super(UsersImplied, user).write(vals) gs = set(concat(g.trans_implied_ids for g in user.groups_id)) |
