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.

63 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # This module copyright (C) 2013 Daniel Reis
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import fields, orm
  22. class CompanyLDAP(orm.Model):
  23. _inherit = 'res.company.ldap'
  24. _columns = {
  25. 'name_attribute': fields.char('Name Attribute', size=64,
  26. help="Default in 'cn'. For an AD you could use 'displayName' instead."),
  27. 'mail_attribute': fields.char('E-mail attribute', size=64,
  28. help="Active Directory uses the 'mail' attribute."),
  29. }
  30. _defaults = {
  31. 'mail_attribute': 'mail',
  32. }
  33. def get_ldap_dicts(self, cr, ids=None):
  34. """
  35. Copy of auth_ldap's funtion, changing only the SQL, so that it returns
  36. all fields in the table.
  37. """
  38. if ids:
  39. id_clause = 'AND id IN (%s)'
  40. args = [tuple(ids)]
  41. else:
  42. id_clause = ''
  43. args = []
  44. cr.execute("""
  45. SELECT *
  46. FROM res_company_ldap
  47. WHERE ldap_server != '' """ + id_clause + """ ORDER BY sequence
  48. """, args)
  49. return cr.dictfetchall()
  50. def map_ldap_attributes(self, cr, uid, conf, login, ldap_entry):
  51. values = super(CompanyLDAP, self).map_ldap_attributes(cr, uid, conf,
  52. login, ldap_entry)
  53. if conf.get('name_attribute'):
  54. values['name'] = ldap_entry[1][conf['name_attribute']][0]
  55. if conf.get('mail_attribute'):
  56. values['email'] = ldap_entry[1][conf['mail_attribute']][0]
  57. return values