From: Dan Scott Date: Tue, 24 Jan 2012 21:32:31 +0000 (-0500) Subject: Generate email addresses where none are in LDAP X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=97e0c8c802ce189a32dde377ecc37fadcf6c5907;p=contrib%2FConifer.git 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 --- 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