[IMP] add an 'active' field on ir.model.access and ir.rule objects
authorAlexis de Lattre <alexis@via.ecp.fr>
Fri, 13 Jul 2012 17:37:34 +0000 (19:37 +0200)
committerAlexis de Lattre <alexis@via.ecp.fr>
Fri, 13 Jul 2012 17:37:34 +0000 (19:37 +0200)
bzr revid: alexis@via.ecp.fr-20120713173734-2m7496qzm82gko5j

openerp/addons/base/ir/ir.xml
openerp/addons/base/ir/ir_model.py
openerp/addons/base/ir/ir_rule.py
openerp/addons/base/res/res_users_view.xml

index 4de12d8..f1b3ca7 100644 (file)
                    <sheet>
                     <group col="4">
                         <field name="name"/>
+                        <field name="active"/>
                         <field name="model_id"/>
                         <field name="group_id"/>
                     </group>
                     <group>
                         <group string="General">
                             <field colspan="4" name="name"/>
+                            <field name="active"/>
                             <field name="model_id"/>
                         </group>
                         <group col="4" string="Access Rights">
index beed30a..f6e9306 100644 (file)
@@ -462,6 +462,7 @@ class ir_model_access(osv.osv):
     _name = 'ir.model.access'
     _columns = {
         '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'),
         'group_id': fields.many2one('res.groups', 'Group', ondelete='cascade', select=True),
         'perm_read': fields.boolean('Read Access'),
@@ -470,6 +471,10 @@ class ir_model_access(osv.osv):
         'perm_unlink': fields.boolean('Delete Access'),
     }
 
+    _defaults = {
+        'active': True,
+    }
+
     def check_groups(self, cr, uid, group):
         grouparr  = group.split('.')
         if not grouparr:
@@ -493,14 +498,16 @@ class ir_model_access(osv.osv):
             cr.execute("SELECT perm_" + mode + " "
                    "  FROM ir_model_access a "
                    "  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()
             if r is None:
                 cr.execute("SELECT perm_" + mode + " "
                        "  FROM ir_model_access a "
                        "  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()
 
@@ -525,6 +532,7 @@ class ir_model_access(osv.osv):
                         LEFT JOIN ir_module_category c ON (c.id=g.category_id)
                       WHERE
                         m.model=%s AND
+                        a.active IS True AND
                         a.perm_''' + access_mode, (model_name,))
         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) '
                    ' WHERE m.model = %s '
                    '   AND gu.uid = %s '
+                   '   AND a.active IS True '
                    , (model_name, uid,)
                    )
         r = cr.fetchone()[0]
@@ -565,6 +574,7 @@ class ir_model_access(osv.osv):
                        '  JOIN ir_model m ON (m.id = a.model_id) '
                        ' WHERE a.group_id IS NULL '
                        '   AND m.model = %s '
+                       '   AND a.active IS True '
                        , (model_name,)
                        )
             r = cr.fetchone()[0]
index 2b864a7..ac16855 100644 (file)
@@ -75,6 +75,7 @@ class ir_rule(osv.osv):
 
     _columns = {
         '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"),
         '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'),
@@ -89,6 +90,7 @@ class ir_rule(osv.osv):
     _order = 'model_id DESC'
 
     _defaults = {
+        'active': True,
         'perm_read': True,
         'perm_write': True,
         'perm_create': True,
@@ -114,6 +116,7 @@ class ir_rule(osv.osv):
                 FROM ir_rule r
                 JOIN ir_model m ON (r.model_id = m.id)
                 WHERE m.model = %s
+                AND r.active is True
                 AND r.perm_""" + mode + """
                 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)
index 1d934b5..32955df 100644 (file)
@@ -37,7 +37,9 @@
                                 <form string="Access Controls" version="7.0">
                                     <group col="4">
                                         <field name="name"/>
+                                        <field name="active"/>
                                         <field name="model_id"/>
+                                        <newline/>
                                         <field name="perm_read"/>
                                         <field name="perm_write"/>
                                         <field name="perm_create"/>