Generate email addresses where none are in LDAP
authorDan Scott <dscott@laurentian.ca>
Tue, 24 Jan 2012 21:32:31 +0000 (16:32 -0500)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 18:57:31 +0000 (14:57 -0400)
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 <dscott@laurentian.ca>
tools/patron-load/ldap_osrf_sync

index 5e26823..5f0795c 100755 (executable)
@@ -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