Browse Source

FIX Tolerate attribute inexistance

pull/2/head
Daniel Reis 11 years ago
parent
commit
9301493482
  1. 16
      users_ldap_mail/users_ldap_model.py

16
users_ldap_mail/users_ldap_model.py

@ -21,6 +21,8 @@
from openerp.osv import fields, orm from openerp.osv import fields, orm
import logging
_log = logging.getLogger(__name__)
class CompanyLDAP(orm.Model): class CompanyLDAP(orm.Model):
_inherit = 'res.company.ldap' _inherit = 'res.company.ldap'
@ -55,9 +57,15 @@ class CompanyLDAP(orm.Model):
def map_ldap_attributes(self, cr, uid, conf, login, ldap_entry): def map_ldap_attributes(self, cr, uid, conf, login, ldap_entry):
values = super(CompanyLDAP, self).map_ldap_attributes(cr, uid, conf, values = super(CompanyLDAP, self).map_ldap_attributes(cr, uid, conf,
login, ldap_entry) login, ldap_entry)
if conf.get('name_attribute'):
values['name'] = ldap_entry[1][conf['name_attribute']][0]
if conf.get('mail_attribute'):
values['email'] = ldap_entry[1][conf['mail_attribute']][0]
mapping = [
('name', 'name_attribute'),
('email', 'mail_attribute'),
]
for value_key, conf_name in mapping:
try:
values[value_key] = ldap_entry[1][conf[conf_name]][0]
except KeyError:
_log.warning('No LDAP attribute "%s" found for login "%s"' % (
conf.get(conf_name, values.get('login'))))
return values return values
Loading…
Cancel
Save