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.

37 lines
1.4 KiB

  1. # Copyright 2016 Camptocamp SA
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import models, api, exceptions
  4. class Base(models.AbstractModel):
  5. """ The base model, which is implicitly inherited by all models. """
  6. _inherit = 'base'
  7. @api.multi
  8. def check_access_rule_all(self, operations=None):
  9. """Verifies that the operation given by ``operations`` is allowed for
  10. the user according to ir.rules.
  11. If ``operations`` is empty, it returns the result for all actions.
  12. :param operation: a list of ``read``, ``create``, ``write``, ``unlink``
  13. :return: {operation: access} (access is a boolean)
  14. """
  15. if not operations or not any(operations):
  16. operations = ['read', 'create', 'write', 'unlink']
  17. result = {}
  18. for operation in operations:
  19. if self.is_transient() or not self.ids:
  20. # If we call check_access_rule() without id, it will try to
  21. # run a SELECT without ID which will crash, so we just blindly
  22. # allow the operations
  23. result[operation] = True
  24. continue
  25. try:
  26. self.check_access_rule(operation)
  27. except exceptions.AccessError:
  28. result[operation] = False
  29. else:
  30. result[operation] = True
  31. return result