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.

39 lines
1.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Anubía, soluciones en la nube,SL (http://www.anubia.es)
  3. # Copyright 2017 Onestein (http://www.onestein.eu)
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  5. import logging
  6. from odoo import api, models
  7. _logger = logging.getLogger(__name__)
  8. class Base(models.AbstractModel):
  9. _inherit = 'base'
  10. @api.model
  11. def load(self, fields, data):
  12. '''Overriding this method we only allow its execution
  13. if current user belongs to the group allowed for CSV data import.
  14. An exception is raised otherwise, and also log the import attempt.
  15. '''
  16. current_user = self.env.user
  17. allowed_group = 'base_import_security_group.group_import_csv'
  18. allowed_group_id = self.env.ref(
  19. allowed_group,
  20. raise_if_not_found=False
  21. )
  22. if not allowed_group_id or current_user.has_group(allowed_group):
  23. res = super(Base, self).load(fields=fields, data=data)
  24. else:
  25. msg = ('User (ID: %s) is not allowed to import data '
  26. 'in model %s.') % (self.env.uid, self._name)
  27. _logger.info(msg)
  28. messages = []
  29. info = {}
  30. messages.append(
  31. dict(info, type='error', message=msg, moreinfo=None))
  32. res = {'ids': None, 'messages': messages}
  33. return res