From d9ef56a6cbbc21c93c5a9b9b3a2eaed8fda7f077 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Tue, 24 Jan 2012 16:32:31 -0500 Subject: [PATCH] Generate email addresses where none are in LDAP Per discussion with MLaferriere, we should expect to see LDAP entries without a 'mail' attribute, and should build email addresses based on the CN. For additional flourish, append @laurentian.ca or @laurentienne.ca based on the language preference. Signed-off-by: Dan Scott --- tools/patron-load/ldap_osrf_sync | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/patron-load/ldap_osrf_sync b/tools/patron-load/ldap_osrf_sync index 5e26823a7a..5f0795caa5 100755 --- a/tools/patron-load/ldap_osrf_sync +++ b/tools/patron-load/ldap_osrf_sync @@ -80,15 +80,22 @@ class User: self.cname = raw_ldap[0] self.ldap_atts = raw_ldap[1] + self.lang_pref = self._simple_map('preferredLanguage') + if 'mail' not in self.ldap_atts: - print >> sys.stderr, 'mail not found for %s' % self.cname + if self.lang_pref and self.lang_pref == 'f': + self.email = self.cname + '@laurentienne.ca' + else: + self.email = self.cname + '@laurentian.ca' + print >> sys.stderr, '"mail" not found for %s, using %s' % (self.cname, self.email) # return None + else: + self.email = (self._simple_map('mail') or '').lower() # Strip leading/ending whitespace; LDAP data can be dirty # Using email for username deliberately here - self.usrname = (self._simple_map('mail') or '').lower() - self.email = (self._simple_map('mail') or '').lower() + self.usrname = self.email self.family_name = self._simple_map('sn') self.ident_type, self.ident_value = self.get_identity() self.home_ou = self.get_home_ou() @@ -96,7 +103,6 @@ class User: if not self.first_given_name: self.first_given_name = 'LDAP_NULL' print >> sys.stderr, 'No givenName for %s' % (self.usrname) - self.lang_pref = self._simple_map('preferredLanguage') # Randomized password, assuming user will use "Forgot password" # function to set their own password -- 2.11.0