[IMP] base : adds direct access to groups, record rules and access rights from user form

Adds 3 smart buttons with count to see :
- Groups
- Access Controls
- Record Rules
Buttons available in debug mode only
Every user that have access to user form has at least admin / Settings or Admin / Access rights.
Admin / Settings includes Admin / Access Rights

Create and delete are not allowed for those views.
Indeed users may think they are modifying current user's access
whereas they are modifying the whole group access.
To avoid confusion, the user's access rights list is now not editable.
Clicking on a row redirects to form view that can be edited.
A warning has been added on access rights form to be sure the user
is aware of what he is doing.

Task ID : 1830142
Closes PR #25587

Co-authored-by: David Beguin <dbe@odoo.com>
Co-authored-by: FMDL <florent.mirieu@gmail.com>
This commit is contained in:
David Beguin
2018-10-24 07:31:06 +00:00
committed by Thibault Delavallée
co-authored by FMDL
parent 70560d1f11
commit 0b1a3da01f
5 changed files with 88 additions and 2 deletions
+1
View File
@@ -1118,6 +1118,7 @@ class IrModelRelation(models.Model):
class IrModelAccess(models.Model):
_name = 'ir.model.access'
_description = 'Model Access'
_order = 'model_id,group_id,name,id'
name = fields.Char(required=True, index=True)
active = fields.Boolean(default=True, help='If you uncheck the active field, it will disable the ACL without deleting it (if you delete a native ACL, it will be re-created when you reload the module).')
+1 -1
View File
@@ -13,7 +13,7 @@ from odoo.tools.safe_eval import safe_eval
class IrRule(models.Model):
_name = 'ir.rule'
_description = 'Record Rule'
_order = 'model_id DESC'
_order = 'model_id DESC,id'
_MODES = ['read', 'write', 'create', 'unlink']
name = fields.Char(index=True)
+54
View File
@@ -251,6 +251,13 @@ class Users(models.Model):
name = fields.Char(related='partner_id.name', inherited=True, readonly=False)
email = fields.Char(related='partner_id.email', inherited=True, readonly=False)
accesses_count = fields.Integer('# Access Rights', help='Number of access rights that apply to the current user',
compute='_compute_accesses_count')
rules_count = fields.Integer('# Record Rules', help='Number of record rules that apply to the current user',
compute='_compute_accesses_count')
groups_count = fields.Integer('# Groups', help='Number of groups that apply to the current user',
compute='_compute_accesses_count')
_sql_constraints = [
('login_key', 'UNIQUE (login)', 'You can not have two users with the same login !')
]
@@ -350,6 +357,14 @@ class Users(models.Model):
for user in self:
user.tz_offset = datetime.datetime.now(pytz.timezone(user.tz or 'GMT')).strftime('%z')
@api.depends('groups_id')
def _compute_accesses_count(self):
for user in self:
groups = user.groups_id
user.accesses_count = len(groups.mapped('model_access'))
user.rules_count = len(groups.mapped('rule_groups'))
user.groups_count = len(groups)
@api.onchange('login')
def on_change_login(self):
if self.login and tools.single_email_re.match(self.login):
@@ -697,6 +712,45 @@ class Users(models.Model):
# for a few places explicitly clearing the has_group cache
has_group.clear_cache = _has_group.clear_cache
def action_show_groups(self):
self.ensure_one()
return {
'name': _('Groups'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'res.groups',
'type': 'ir.actions.act_window',
'context': {'create': False, 'delete': False},
'domain': [('id','in', self.groups_id.ids)],
'target': 'current',
}
def action_show_accesses(self):
self.ensure_one()
return {
'name': _('Access Rights'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'ir.model.access',
'type': 'ir.actions.act_window',
'context': {'create': False, 'delete': False},
'domain': [('id', 'in', self.mapped('groups_id.model_access').ids)],
'target': 'current',
}
def action_show_rules(self):
self.ensure_one()
return {
'name': _('Record Rules'),
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'ir.rule',
'type': 'ir.actions.act_window',
'context': {'create': False, 'delete': False},
'domain': [('id', 'in', self.mapped('groups_id.rule_groups').ids)],
'target': 'current',
}
@api.multi
def _is_public(self):
self.ensure_one()
+23 -1
View File
@@ -530,6 +530,25 @@
<!-- ir.model.access -->
<record id="ir_access_view_tree" model="ir.ui.view">
<field name="name">ir.model.access.view.tree</field>
<field name="model">ir.model.access</field>
<field name="arch" type="xml">
<tree string="Access Rights"
decoration-warning="not group_id and
(perm_read or perm_write or
perm_create or perm_unlink)">
<field name="name"/>
<field name="model_id"/>
<field name="group_id"/>
<field name="perm_read"/>
<field name="perm_write"/>
<field name="perm_create"/>
<field name="perm_unlink"/>
</tree>
</field>
</record>
<record id="ir_access_view_tree_edition" model="ir.ui.view">
<field name="name">ir.model.access.view.tree.edition</field>
<field name="model">ir.model.access</field>
<field name="arch" type="xml">
<tree string="Access Rights" editable="top"
@@ -551,6 +570,9 @@
<field name="arch" type="xml">
<form string="Access Rights">
<sheet>
<div class="alert alert-warning text-center" role="alert">
Please note that modifications will be applied for all users of the specified group
</div>
<group col="4">
<field name="name"/>
<field name="model_id"/>
@@ -590,7 +612,7 @@
<field name="name">Access Rights</field>
<field name="res_model">ir.model.access</field>
<field name="view_type">form</field>
<field name="view_id" ref="ir_access_view_tree"/>
<field name="view_id" ref="ir_access_view_tree_edition"/>
<field name="search_view_id" ref="ir_access_view_search"/>
</record>
<menuitem action="ir_access_act" id="menu_ir_access_act" parent="base.menu_security"/>
@@ -163,6 +163,15 @@
<sheet>
<field name="id" invisible="1"/>
<div class="oe_button_box" name="button_box">
<button name="action_show_groups" type="object" groups="base.group_no_one" class="oe_stat_button" icon="fa-users">
<field string="Groups" name="groups_count" widget="statinfo"/>
</button>
<button name="action_show_accesses" type="object" groups="base.group_no_one" class="oe_stat_button" icon="fa-list">
<field string="Access Rights" name="accesses_count" widget="statinfo"/>
</button>
<button name="action_show_rules" type="object" groups="base.group_no_one" class="oe_stat_button" icon="fa-list-ul">
<field string="Record Rules" name="rules_count" widget="statinfo"/>
</button>
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-check">
<field name="active" widget="boolean_button" options='{"terminology": "active"}'/>
</button>