Skip to content

Commit

Permalink
[IMP] base_user_role: users validation
Browse files Browse the repository at this point in the history
  • Loading branch information
polqubiq committed Nov 21, 2023
1 parent effcddb commit 89067fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base_user_role/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -129,6 +130,16 @@ def show_model_access_ids(self):
action["domain"] = [("id", "in", self.model_access_ids.ids)]
return action

@api.constrains("line_ids")
def restriction_users_role(self):
for role in self:
admin_role = self.env.ref("base.user_admin")
users = role.line_ids.mapped("user_id")
if admin_role in users:
raise ValidationError(

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

View check run for this annotation

Codecov / codecov/patch

base_user_role/models/role.py#L139

Added line #L139 was not covered by tests
_("You cannot add the administrator user to the users role.")
)


class ResUsersRoleLine(models.Model):
_name = "res.users.role.line"
Expand Down

0 comments on commit 89067fa

Please sign in to comment.