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.

52 lines
1.8 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author Nicolas Bessi. Copyright Camptocamp SA
  5. ##############################################################################
  6. from osv import 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(
  14. cr, uid, 'protect_security?', default=False, context=context)
  15. if on in (1, "1", "YES", True):
  16. if context.get('manual_security_override', False):
  17. return True
  18. return False
  19. else:
  20. return True
  21. def write(self, cr, uid, ids, vals, context=None):
  22. res = True
  23. context = context or {}
  24. if self._acces_can_be_modified(cr, uid, context=context):
  25. res = super(IrModelAccess, self).write(
  26. cr, uid, ids, vals, context=context)
  27. return res
  28. def unlink(self, cr, uid, ids, context=None):
  29. res = True
  30. context = context or {}
  31. # I'm note sur about this one maybe we should do nothing
  32. if self._acces_can_be_modified(cr, uid, context=context):
  33. vals = {
  34. 'perm_read': False,
  35. 'perm_write': False,
  36. 'perm_unlink': False,
  37. 'perm_create': False
  38. }
  39. super(IrModelAccess, self).write(
  40. cr, uid, ids, vals, context=context)
  41. else:
  42. res = super(IrModelAccess, self).unlink(
  43. cr, uid, ids, context=context)
  44. return res
  45. IrModelAccess()