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.

28 lines
932 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. IMMUTABLE = 'user_immutable.group_immutable'
  7. class ResGroups(models.Model):
  8. _inherit = 'res.groups'
  9. @api.multi
  10. def write(self, vals):
  11. """ Override write to verify that access to the `Immutable` group is
  12. not given or removed by users without access
  13. """
  14. if not vals.get('users') or self.env.user.has_group(IMMUTABLE):
  15. return super(ResGroups, self).write(vals)
  16. immutable = self.env.ref(IMMUTABLE, raise_if_not_found=False)
  17. if immutable and immutable in self:
  18. raise AccessError(_(
  19. 'You must be a member of the `Immutable` group to grant'
  20. ' access to it'
  21. ))
  22. return super(ResGroups, self).write(vals)