From 48427fb8583bb0bced3b8d687c180629d0d3d3b7 Mon Sep 17 00:00:00 2001 From: "Kevin.roche" Date: Mon, 27 Jun 2022 17:16:43 +0200 Subject: [PATCH] [IMP] base_user_role show rules and access --- base_user_role/models/group.py | 4 ---- base_user_role/models/role.py | 36 ++++++++++++++++++++++++++++++++++ base_user_role/views/role.xml | 26 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/base_user_role/models/group.py b/base_user_role/models/group.py index 61e608549..840df8c62 100644 --- a/base_user_role/models/group.py +++ b/base_user_role/models/group.py @@ -13,7 +13,6 @@ class ResGroups(models.Model): inverse_name="group_id", help="Relation for the groups that represents a role", ) - role_ids = fields.Many2many( comodel_name="res.users.role", relation="res_groups_implied_roles_rel", @@ -21,7 +20,6 @@ class ResGroups(models.Model): compute="_compute_role_ids", help="Roles in which the group is involved", ) - parent_ids = fields.Many2many( "res.groups", "res_groups_implied_rel", @@ -31,13 +29,11 @@ class ResGroups(models.Model): help="Inverse relation for the Inherits field. " "The groups from which this group is inheriting", ) - trans_parent_ids = fields.Many2many( comodel_name="res.groups", string="Parent Groups", compute="_compute_trans_parent_ids", ) - role_count = fields.Integer("# Roles", compute="_compute_role_count") def _compute_role_count(self): diff --git a/base_user_role/models/role.py b/base_user_role/models/role.py index caa08a83f..f6a5d8387 100644 --- a/base_user_role/models/role.py +++ b/base_user_role/models/role.py @@ -26,6 +26,20 @@ class ResUsersRole(models.Model): user_ids = fields.One2many( comodel_name="res.users", string="Users list", compute="_compute_user_ids" ) + rule_ids = fields.Many2many( + comodel_name="ir.rule", + compute="_compute_rule_ids", + string="Record Rules", + required=False, + ) + rules_count = fields.Integer(compute="_compute_rule_ids") + model_access_ids = fields.Many2many( + comodel_name="ir.model.access", + compute="_compute_model_access_ids", + string="Access Rights", + required=False, + ) + model_access_count = fields.Integer(compute="_compute_model_access_ids") group_category_id = fields.Many2one( related="group_id.category_id", default=lambda cls: cls.env.ref("base_user_role.ir_module_category_role").id, @@ -39,6 +53,18 @@ def _compute_user_ids(self): for role in self: role.user_ids = role.line_ids.mapped("user_id") + @api.depends("implied_ids", "implied_ids.model_access") + def _compute_model_access_ids(self): + for rec in self: + rec.model_access_ids = rec.implied_ids.model_access.ids + rec.model_access_count = len(rec.model_access_ids) + + @api.depends("implied_ids", "implied_ids.rule_groups") + def _compute_rule_ids(self): + for rec in self: + rec.rule_ids = rec.implied_ids.rule_groups.ids + rec.rules_count = len(rec.rule_ids) + @api.model def create(self, vals): new_record = super(ResUsersRole, self).create(vals) @@ -75,6 +101,16 @@ def cron_update_users(self): logging.info("Update user roles") self.search([]).update_users() + def show_rule_ids(self): + action = self.env["ir.actions.actions"]._for_xml_id("base.action_rule") + action["domain"] = [("id", "in", self.rule_ids.ids)] + return action + + def show_model_access_ids(self): + action = self.env["ir.actions.actions"]._for_xml_id("base.ir_access_act") + action["domain"] = [("id", "in", self.model_access_ids.ids)] + return action + class ResUsersRoleLine(models.Model): _name = "res.users.role.line" diff --git a/base_user_role/views/role.xml b/base_user_role/views/role.xml index 400686515..5d8f3cbdb 100644 --- a/base_user_role/views/role.xml +++ b/base_user_role/views/role.xml @@ -9,6 +9,32 @@
+
+ + +