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.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. import os
  5. from odoo import _, api, models
  6. from odoo.exceptions import AccessError
  7. from .res_groups import THRESHOLD_MANAGER
  8. MAX_DB_USER_PARAM = 'user.threshold.database'
  9. THRESHOLD_HIDE = str(os.environ.get('USER_THRESHOLD_HIDE', '')) == '1'
  10. class IrConfigParameter(models.Model):
  11. _inherit = 'ir.config_parameter'
  12. @api.multi
  13. def unlink(self):
  14. """
  15. Override to disallow deletion of the user threshold parameter
  16. when the user does not have the right access
  17. """
  18. for rec in self.filtered(lambda r: r.key == MAX_DB_USER_PARAM):
  19. if not self.env.user.has_group(THRESHOLD_MANAGER):
  20. raise AccessError(_(
  21. 'You must be a member of the `User Threshold Manager` '
  22. 'to delete this parameter'
  23. ))
  24. return super(IrConfigParameter, self).unlink()
  25. @api.multi
  26. def write(self, vals):
  27. """
  28. Override to disallow manipulation of the user threshold parameter
  29. when the user does not have the right access
  30. """
  31. for rec in self.filtered(lambda r: r.key == MAX_DB_USER_PARAM):
  32. if not self.env.user.has_group(THRESHOLD_MANAGER):
  33. raise AccessError(_(
  34. 'You must be a member of the `User Threshold Manager` '
  35. 'to set this parameter'
  36. ))
  37. return super(IrConfigParameter, self).write(vals)