[FIX+IMP] base_user_role: Several things:

* FIX: Update users' groups when a role is deleted
* IMP: add some test cases to check user's groups when its last role line is removed
* FIX: ensure that the user's groups are updated when its last role line is removed
This commit is contained in:
sebalix
2017-09-21 11:21:34 +02:00
committed by Jesús Alan Ramos Rodríguez
parent 961f983cd3
commit 3d408dc663
3 changed files with 62 additions and 4 deletions

View File

@@ -46,6 +46,13 @@ class ResUsersRole(models.Model):
self.update_users()
return res
@api.multi
def unlink(self):
users = self.mapped('user_ids')
res = super(ResUsersRole, self).unlink()
users.set_groups_from_roles(force=True)
return res
@api.multi
def update_users(self):
"""Update all the users concerned by the roles identified by `ids`."""
@@ -91,5 +98,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

View File

@@ -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(