Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] base_user_role: warning when adding admin to empty role #308

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions base_user_role/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,16 @@
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 {

Check warning on line 182 in base_user_role/models/role.py

View check run for this annotation

Codecov / codecov/patch

base_user_role/models/role.py#L182

Added line #L182 was not covered by tests
"warning": {
"title": _("Warning"),
"message": _(
"""When adding a role to an administrator,
make sure no essential groups will be removed."""
),
}
}
15 changes: 14 additions & 1 deletion base_user_role/models/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2014 ABF OSIELL <http://osiell.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo import api, fields, models
from odoo import _, api, fields, models


class ResUsers(models.Model):
Expand All @@ -19,6 +19,19 @@
compute_sudo=True,
)

@api.onchange("role_line_ids")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of a computed boolean field to display or not a <div class="alert alert-warning" role="alert"> in the forms, less intrusive than a popup. What do you think?

def _onchange_role_line_ids(self):
if self._is_admin():
return {

Check warning on line 25 in base_user_role/models/user.py

View check run for this annotation

Codecov / codecov/patch

base_user_role/models/user.py#L25

Added line #L25 was not covered by tests
"warning": {
"title": _("Warning"),
"message": _(
"""When adding a role to an administrator,
make sure no essential groups will be removed."""
),
}
}

@api.model
def _default_role_lines(self):
default_user = self.env.ref("base.default_user", raise_if_not_found=False)
Expand Down
Loading