You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.8 KiB

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