[IMP] base_user_role: Adding alert in user when role is used

This commit is contained in:
Jesus Ramoneda
2023-06-07 16:29:31 +02:00
committed by Christopher Rogos
parent fe74ac99ed
commit b7578b9034
3 changed files with 37 additions and 0 deletions

View File

@@ -12,6 +12,14 @@ class ResUsers(models.Model):
string="Role lines", string="Role lines",
default=lambda self: self._default_role_lines(), default=lambda self: self._default_role_lines(),
) )
show_alert = fields.Boolean(compute="_compute_show_alert")
@api.depends("role_line_ids")
def _compute_show_alert(self):
for user in self:
user.show_alert = user.role_line_ids.filtered(lambda rec: rec.is_enabled)
role_ids = fields.One2many( role_ids = fields.One2many(
comodel_name="res.users.role", comodel_name="res.users.role",
string="Roles", string="Roles",

View File

@@ -247,6 +247,15 @@ class TestUserRole(TransactionCase):
role_group_ids = sorted(set(role.trans_implied_ids.ids)) role_group_ids = sorted(set(role.trans_implied_ids.ids))
self.assertEqual(user_group_ids, role_group_ids) self.assertEqual(user_group_ids, role_group_ids)
def test_show_alert_computation(self):
"""Test the computation of the `show_alert` field."""
self.user_id.write({"role_line_ids": [(0, 0, {"role_id": self.role1_id.id})]})
self.assertTrue(self.user_id.show_alert)
# disable role
self.user_id.role_line_ids.unlink()
self.assertFalse(self.user_id.show_alert)
def test_group_groups_into_role(self): def test_group_groups_into_role(self):
user_group_ids = [group.id for group in self.user_id.groups_id] user_group_ids = [group.id for group in self.user_id.groups_id]
# Check that there is not a role with name: Test Role # Check that there is not a role with name: Test Role

View File

@@ -24,8 +24,28 @@
</field> </field>
</page> </page>
</xpath> </xpath>
<xpath expr="//page[@name='access_rights']/group" position="before">
<field name="show_alert" invisible="1" />
<div
class="alert alert-info text-center o_form_header"
invisible="not show_alert"
role="alert"
>
<div>
<strong
>The access rights of this user are managed by roles.</strong>
</div>
<div>
<em
>Any configuration changes made here will not be persistent.</em>
</div>
<a class="close" data-bs-dismiss="alert" href="#">x</a>
</div>
</xpath>
</field> </field>
</record> </record>
<record id="view_res_users_search_inherit" model="ir.ui.view"> <record id="view_res_users_search_inherit" model="ir.ui.view">
<field name="name">res.users.search.inherit</field> <field name="name">res.users.search.inherit</field>
<field name="model">res.users</field> <field name="model">res.users</field>