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
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2018 Therp BV <https://therp.nl>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo import SUPERUSER_ID, api, models, registry
  5. class ResUsers(models.Model):
  6. _inherit = 'res.users'
  7. @classmethod
  8. def _login(cls, db, login, password):
  9. user_id = super(ResUsers, cls)._login(db, login, password)
  10. if not user_id:
  11. return user_id
  12. with registry(db).cursor() as cr:
  13. env = api.Environment(cr, SUPERUSER_ID, {})
  14. user = env['res.users'].browse(user_id)
  15. # check if this user came from ldap, rerun get_or_create_user in
  16. # this case to apply ldap groups if necessary
  17. ldaps = user.company_id.ldaps
  18. if user.active and any(ldaps.mapped('only_ldap_groups')):
  19. for conf in ldaps.get_ldap_dicts():
  20. entry = ldaps.authenticate(conf, login, password)
  21. if entry:
  22. ldaps.get_or_create_user(conf, login, entry)
  23. break
  24. return user_id