~therp-nl/server-env-tools/6.1-web_base_url_freeze

« back to all changes in this revision

Viewing changes to security_protector/security_protector.py

  • Committer: nicolas.bessi at camptocamp
  • Date: 2012-02-14 10:17:16 UTC
  • Revision ID: nicolas.bessi@camptocamp.com-20120214101716-h4mniuel9xd82rrb
[ADD] security protector
(lp:c2c-addons/6.1  rev 37)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Author Nicolas Bessi. Copyright Camptocamp SA
 
5
##############################################################################
 
6
from osv import fields, osv
 
7
 
 
8
class IrModelAccess(osv.osv):
 
9
    "We inherit ir model access to add specific write unlink and copy behavior"
 
10
    _name = 'ir.model.access'
 
11
    _inherit = "ir.model.access"
 
12
                    
 
13
    def _acces_can_be_modified(self, cr, uid, context=None):
 
14
        context = context or {}
 
15
        on = self.pool.get('ir.config_parameter').get_param(cr, uid, 'protect_security?', default=False, context=context)
 
16
        if on in (1, "1", "YES", True):
 
17
            if context.get('manual_security_override', False):
 
18
                return True
 
19
            return False
 
20
            
 
21
        else:
 
22
            return True
 
23
        
 
24
    def write(self, cr, uid, ids, vals, context=None):
 
25
        res =True
 
26
        context = context or {}
 
27
        if self._acces_can_be_modified(cr, uid, context=context):
 
28
            res = super(IrModelAccess, self).write(cr, uid, ids, vals, context=context)
 
29
        return res
 
30
 
 
31
 
 
32
    def unlink(self, cr, uid, ids, context=None):
 
33
        res = True
 
34
        context = context or {}
 
35
        if self._acces_can_be_modified(cr, uid, context=context):
 
36
            res = super(IrModelAccess, self).write(cr, uid, ids, context=context)
 
37
        else: # I'm note sur about this one maybe we should do nothing
 
38
            self.write(cr, uid, args[0], 
 
39
                       {'perm_read':False,
 
40
                        'perm_write': False, 
 
41
                        'perm_unlink': False,
 
42
                        'perm_create': False}, 
 
43
                       context={context})
 
44
        return res
 
45
        
 
46
IrModelAccess()
 
 
b'\\ No newline at end of file'