Browse Source

[FIX] base_user_role: ensure that the user's groups are updated when its last role line is removed

pull/1066/head
sebalix 7 years ago
parent
commit
45c766903e
  1. 4
      base_user_role/models/role.py
  2. 7
      base_user_role/models/user.py

4
base_user_role/models/role.py

@ -52,7 +52,7 @@ class ResUsersRole(models.Model):
def unlink(self):
users = self.mapped('user_ids')
res = super(ResUsersRole, self).unlink()
users.set_groups_from_roles()
users.set_groups_from_roles(force=True)
return res
@api.multi
@ -99,5 +99,5 @@ class ResUsersRoleLine(models.Model):
def unlink(self):
users = self.mapped('user_id')
res = super(ResUsersRoleLine, self).unlink()
users.set_groups_from_roles()
users.set_groups_from_roles(force=True)
return res

7
base_user_role/models/user.py

@ -32,12 +32,13 @@ class ResUsers(models.Model):
return res
@api.multi
def set_groups_from_roles(self):
def set_groups_from_roles(self, force=False):
"""Set (replace) the groups following the roles defined on users.
If no role is defined on the user, its groups are let untouched.
If no role is defined on the user, its groups are let untouched unless
the `force` parameter is `True`.
"""
for user in self:
if not user.role_line_ids:
if not user.role_line_ids and not force:
continue
group_ids = []
role_lines = user.role_line_ids.filtered(

Loading…
Cancel
Save