Skip to content

Commit

Permalink
[14.0] base_user_role: warning when adding admin to role
Browse files Browse the repository at this point in the history
When creating a new user role, it is possible to add a user to that role without having added any groups.
If this is saved, all that user’s access rights will be wiped and he will not able to login anymore (Internal Server Error).
  • Loading branch information
ajaniszewska-dev committed Sep 6, 2024
1 parent 41b41f5 commit d52fde8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base_user_role/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,11 @@ def unlink(self):
res = super(ResUsersRoleLine, self).unlink()
users.set_groups_from_roles(force=True)
return res

@api.onchange('user_id')
def _onchange_user_id(self):
if self.user_id and self.user_id._is_admin():
return {'warning': {
'title': _("Warning"),
'message': _("When adding a role to an administrator, make sure no essential groups will be removed."),
}}

0 comments on commit d52fde8

Please sign in to comment.