[IMP] add an 'active' field on ir.model.access and ir.rule objects

bzr revid: alexis@via.ecp.fr-20120713173734-2m7496qzm82gko5j
This commit is contained in:
Alexis de Lattre 2012-07-13 19:37:34 +02:00
parent 961dff11ea
commit c28e975ee7
4 changed files with 19 additions and 2 deletions

View File

@ -1539,6 +1539,7 @@
<sheet> <sheet>
<group col="4"> <group col="4">
<field name="name"/> <field name="name"/>
<field name="active"/>
<field name="model_id"/> <field name="model_id"/>
<field name="group_id"/> <field name="group_id"/>
</group> </group>
@ -1599,6 +1600,7 @@
<group> <group>
<group string="General"> <group string="General">
<field colspan="4" name="name"/> <field colspan="4" name="name"/>
<field name="active"/>
<field name="model_id"/> <field name="model_id"/>
</group> </group>
<group col="4" string="Access Rights"> <group col="4" string="Access Rights">

View File

@ -462,6 +462,7 @@ class ir_model_access(osv.osv):
_name = 'ir.model.access' _name = 'ir.model.access'
_columns = { _columns = {
'name': fields.char('Name', size=64, required=True, select=True), 'name': fields.char('Name', size=64, required=True, select=True),
'active': fields.boolean('Active', 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.'),
'model_id': fields.many2one('ir.model', 'Object', required=True, domain=[('osv_memory','=', False)], select=True, ondelete='cascade'), 'model_id': fields.many2one('ir.model', 'Object', required=True, domain=[('osv_memory','=', False)], select=True, ondelete='cascade'),
'group_id': fields.many2one('res.groups', 'Group', ondelete='cascade', select=True), 'group_id': fields.many2one('res.groups', 'Group', ondelete='cascade', select=True),
'perm_read': fields.boolean('Read Access'), 'perm_read': fields.boolean('Read Access'),
@ -470,6 +471,10 @@ class ir_model_access(osv.osv):
'perm_unlink': fields.boolean('Delete Access'), 'perm_unlink': fields.boolean('Delete Access'),
} }
_defaults = {
'active': True,
}
def check_groups(self, cr, uid, group): def check_groups(self, cr, uid, group):
grouparr = group.split('.') grouparr = group.split('.')
if not grouparr: if not grouparr:
@ -493,14 +498,16 @@ class ir_model_access(osv.osv):
cr.execute("SELECT perm_" + mode + " " cr.execute("SELECT perm_" + mode + " "
" FROM ir_model_access a " " FROM ir_model_access a "
" JOIN ir_model m ON (m.id = a.model_id) " " JOIN ir_model m ON (m.id = a.model_id) "
" WHERE m.model = %s AND a.group_id = %s", (model_name, group_id) " WHERE m.model = %s AND a.active IS True "
" AND a.group_id = %s", (model_name, group_id)
) )
r = cr.fetchone() r = cr.fetchone()
if r is None: if r is None:
cr.execute("SELECT perm_" + mode + " " cr.execute("SELECT perm_" + mode + " "
" FROM ir_model_access a " " FROM ir_model_access a "
" JOIN ir_model m ON (m.id = a.model_id) " " JOIN ir_model m ON (m.id = a.model_id) "
" WHERE m.model = %s AND a.group_id IS NULL", (model_name, ) " WHERE m.model = %s AND a.active IS True "
" AND a.group_id IS NULL", (model_name, )
) )
r = cr.fetchone() r = cr.fetchone()
@ -525,6 +532,7 @@ class ir_model_access(osv.osv):
LEFT JOIN ir_module_category c ON (c.id=g.category_id) LEFT JOIN ir_module_category c ON (c.id=g.category_id)
WHERE WHERE
m.model=%s AND m.model=%s AND
a.active IS True AND
a.perm_''' + access_mode, (model_name,)) a.perm_''' + access_mode, (model_name,))
return [('%s/%s' % x) if x[0] else x[1] for x in cr.fetchall()] return [('%s/%s' % x) if x[0] else x[1] for x in cr.fetchall()]
@ -554,6 +562,7 @@ class ir_model_access(osv.osv):
' JOIN res_groups_users_rel gu ON (gu.gid = a.group_id) ' ' JOIN res_groups_users_rel gu ON (gu.gid = a.group_id) '
' WHERE m.model = %s ' ' WHERE m.model = %s '
' AND gu.uid = %s ' ' AND gu.uid = %s '
' AND a.active IS True '
, (model_name, uid,) , (model_name, uid,)
) )
r = cr.fetchone()[0] r = cr.fetchone()[0]
@ -565,6 +574,7 @@ class ir_model_access(osv.osv):
' JOIN ir_model m ON (m.id = a.model_id) ' ' JOIN ir_model m ON (m.id = a.model_id) '
' WHERE a.group_id IS NULL ' ' WHERE a.group_id IS NULL '
' AND m.model = %s ' ' AND m.model = %s '
' AND a.active IS True '
, (model_name,) , (model_name,)
) )
r = cr.fetchone()[0] r = cr.fetchone()[0]

View File

@ -75,6 +75,7 @@ class ir_rule(osv.osv):
_columns = { _columns = {
'name': fields.char('Name', size=128, select=1), 'name': fields.char('Name', size=128, select=1),
'active': fields.boolean('Active', help="If you uncheck the active field, it will disable the record rule without deleting it (if you delete a native record rule, it may be re-created when you reload the module."),
'model_id': fields.many2one('ir.model', 'Object',select=1, required=True, ondelete="cascade"), 'model_id': fields.many2one('ir.model', 'Object',select=1, required=True, ondelete="cascade"),
'global': fields.function(_get_value, string='Global', type='boolean', store=True, help="If no group is specified the rule is global and applied to everyone"), 'global': fields.function(_get_value, string='Global', type='boolean', store=True, help="If no group is specified the rule is global and applied to everyone"),
'groups': fields.many2many('res.groups', 'rule_group_rel', 'rule_group_id', 'group_id', 'Groups'), 'groups': fields.many2many('res.groups', 'rule_group_rel', 'rule_group_id', 'group_id', 'Groups'),
@ -89,6 +90,7 @@ class ir_rule(osv.osv):
_order = 'model_id DESC' _order = 'model_id DESC'
_defaults = { _defaults = {
'active': True,
'perm_read': True, 'perm_read': True,
'perm_write': True, 'perm_write': True,
'perm_create': True, 'perm_create': True,
@ -114,6 +116,7 @@ class ir_rule(osv.osv):
FROM ir_rule r FROM ir_rule r
JOIN ir_model m ON (r.model_id = m.id) JOIN ir_model m ON (r.model_id = m.id)
WHERE m.model = %s WHERE m.model = %s
AND r.active is True
AND r.perm_""" + mode + """ AND r.perm_""" + mode + """
AND (r.id IN (SELECT rule_group_id FROM rule_group_rel g_rel AND (r.id IN (SELECT rule_group_id FROM rule_group_rel g_rel
JOIN res_groups_users_rel u_rel ON (g_rel.group_id = u_rel.gid) JOIN res_groups_users_rel u_rel ON (g_rel.group_id = u_rel.gid)

View File

@ -37,7 +37,9 @@
<form string="Access Controls" version="7.0"> <form string="Access Controls" version="7.0">
<group col="4"> <group col="4">
<field name="name"/> <field name="name"/>
<field name="active"/>
<field name="model_id"/> <field name="model_id"/>
<newline/>
<field name="perm_read"/> <field name="perm_read"/>
<field name="perm_write"/> <field name="perm_write"/>
<field name="perm_create"/> <field name="perm_create"/>