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.

27 lines
964 B

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  4. from odoo import _, api, models
  5. from odoo.exceptions import AccessError
  6. THRESHOLD_MANAGER = 'user_threshold.group_threshold_manager'
  7. class ResGroups(models.Model):
  8. _inherit = 'res.groups'
  9. @api.multi
  10. def write(self, vals):
  11. """ Override write to verify that membership of the Threshold Manager
  12. group is not able to be set by users outside that group
  13. """
  14. manager = self.env.ref(THRESHOLD_MANAGER, raise_if_not_found=False)
  15. if manager:
  16. is_manager = self.env.user.has_group(THRESHOLD_MANAGER)
  17. if not is_manager and manager in self:
  18. raise AccessError(_(
  19. 'You must be a member of the `User Threshold Manager` '
  20. 'group to grant access to it.'
  21. ))
  22. return super(ResGroups, self).write(vals)