Skip to content

Commit

Permalink
Merge PR OCA#169 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by sebalix
  • Loading branch information
OCA-git-bot committed Sep 28, 2022
2 parents 4598a03 + 48427fb commit 798ffe2
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
4 changes: 0 additions & 4 deletions base_user_role/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ 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",
string="Roles",
compute="_compute_role_ids",
help="Roles in which the group is involved",
)

parent_ids = fields.Many2many(
"res.groups",
"res_groups_implied_rel",
Expand All @@ -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):
Expand Down
36 changes: 36 additions & 0 deletions base_user_role/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,6 +53,18 @@ def _compute_user_ids(self):
for role in self.sudo() if self._bypass_rules() else 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 _bypass_rules(self):
# Run methods as super user to avoid problems by "Administrator/Access Right"
Expand Down Expand Up @@ -88,6 +114,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"
Expand Down
26 changes: 26 additions & 0 deletions base_user_role/views/role.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@
<field name="arch" type="xml">
<form>
<sheet>
<div class="oe_button_box" name="button_box">
<button
name="show_model_access_ids"
type="object"
class="oe_stat_button"
icon="fa-book"
>
<field
name="model_access_count"
widget="statinfo"
string="Access Rights"
/>
</button>
<button
name="show_rule_ids"
type="object"
class="oe_stat_button"
icon="fa-server"
>
<field
name="rules_count"
widget="statinfo"
string="Record Rules"
/>
</button>
</div>
<group>
<field name="name" />
<field name="group_id" required="0" readonly="1" />
Expand Down

0 comments on commit 798ffe2

Please sign in to comment.