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

7
base_user_role/models/user.py

@ -32,12 +32,13 @@ class ResUsers(models.Model):
return res return res
@api.multi @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. """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: for user in self:
if not user.role_line_ids:
if not user.role_line_ids and not force:
continue continue
group_ids = [] group_ids = []
role_lines = user.role_line_ids.filtered( role_lines = user.role_line_ids.filtered(

Loading…
Cancel
Save