Commits

Zhang Huangbin committed 5ccfe4a

Fix issue while submit empty cn.

  • Participants
  • Parent commits aee03b6
  • Tags 0.1

Comments (0)

Files changed (9)

controllers/ldap/user.py

         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)
 
-        self.result = userLib.update(
+        result = userLib.update(
                 profile_type=self.profile_type,
                 mail=self.mail,
                 data=i,
                 )
-        if self.result is True:
+        if result[0] is True:
             web.seeother('/profile/user/%s/%s?msg=UPDATED_SUCCESS' % (self.profile_type, self.mail))
-        elif self.result[0] is False:
-            web.seeother('/profile/user/%s/%s?msg=%s' % (self.profile_type, self.mail, self.result[1]))
+        else:
+            web.seeother('/profile/user/%s/%s?msg=%s' % (self.profile_type, self.mail, result[1]))
 
 class create(dbinit):
     @base.protected

libs/ldaplib/admin.py

         if self.profile_type == 'general':
             self.lang = web.safestr(data.get('preferredLanguage', 'en_US'))
 
-            mod_attrs = [
-                    (ldap.MOD_REPLACE, 'preferredLanguage', self.lang)
-                    ]
+            mod_attrs += [ (ldap.MOD_REPLACE, 'preferredLanguage', self.lang) ]
 
             cn = data.get('cn', None)
-            if cn is not None and cn != u'' and cn != '':
-                mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
-            #else:
-            #    # Delete attribute.
-            #    mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', '') ]
+            mod_attrs += ldaputils.getModAttrCN(cn, default=self.mail.split('@')[0])
 
             try:
                 # Modify profiles.

libs/ldaplib/domain.py

         mod_attrs = []
         if self.profile_type == 'general':
             cn = data.get('cn', None)
-            if cn is not None:
-                mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
-            else:
-                # Delete attribute.
-                mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', '') ]
+            mod_attrs += ldaputils.getModAttrCN(cn, default=self.domain)
 
         if session.get('domainGlobalAdmin') == 'yes':
             accountStatus = web.safestr(data.get('accountStatus', 'active'))

libs/ldaplib/iredldif.py

             ('enabledService',  enabledService),
             ]
 
-    if cn is not None and cn != u'' and cn != '':
-        ldif += [('cn', [cn.encode('utf-8')])]
+    ldif += ldaputils.getModAttrCN(cn, default=domainName)
 
     return ldif
 
             ('hasMember',       'no'),
             ]
 
-    if cn is not None and cn != u'' and cn != '':
-        ldif += [('cn', cn.encode('utf-8'))]
+    ldif += ldaputils.getModAttrCN(cn, default=group)
 
     if desc is not None:
         ldif += [('description', desc.encode('utf-8'))]
             ('domainGlobalAdmin',   [web.safestr(domainGlobalAdmin)]),
             ]
 
-    if cn is not None and cn != u'' and cn != '':
-        ldif += [('cn', [cn.encode('utf-8')])]
-    else:
-        ldif += [('cn', [mail.split('@', 1)[0]])]
+    ldif += ldaputils.getModAttrCN(cn, default=mail.split('@', 1)[0])
 
     return ldif
 
         ('memberOfGroup',       ['all@'+domain]), # Make all users belong to group 'all@domain.ltd'.
         ]
 
-    if cn is not None and cn != u'' and cn != '':
-        ldif += [('cn', [cn.encode('utf-8')])]
-    else:
-        ldif += [('cn', [username])]
+    ldif += ldaputils.getModAttrCN(cn, default=username)
 
     return ldif

libs/ldaplib/ldaputils.py

             pw = password
 
     return pw
+
+def getModAttrCN(cn, default='None'):
+    if cn is not None and cn != '' and cn != u'':
+        mod_attrs = [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
+    else:
+        # Value is 'None' (string, not NoneType).
+        mod_attrs = [ ( ldap.MOD_REPLACE, 'cn', default ) ]
+
+    return mod_attrs

libs/ldaplib/user.py

         if self.profile_type == 'general':
             # Get cn.
             cn = data.get('cn', None)
-
-            if cn is not None and cn != u'' and cn != '':
-                mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
-            #else:
-            #    # Delete attribute.
-            #    mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', '') ]
+            mod_attrs += ldaputils.getModAttrCN(cn, default=self.mail.split('@')[0])
 
             # Get mail address.
 
         try:
             dn = ldaputils.convEmailToUserDN(self.mail)
             self.conn.modify_s(dn, mod_attrs)
-            return True
+            return (True, 'SUCCESS')
         except Exception, e:
             return (False, str(e))

templates/default/ldap/domain_profile.html

                                 {% endfor %}
                                 </select>
                             </span></span></li>
-                    <li><span><strong>{{ _('Company/Organization') }}</strong> {{cn}}</span></li>
+                        <li><span><strong>{{ _('Company/Organization') }}</strong> {% if cn != 'None' %}{{cn}}{% endif %}</span></li>
                     <li><span><strong>{{ _('Created Date') }}</strong> {{createTimestamp[:4]}}-{{createTimestamp[4:6]}}-{{createTimestamp[6:8]}} {{createTimestamp[8:10]}}:{{createTimestamp[10:12]}}:{{createTimestamp[12:14]}}</span></li>
                 </ul>
             </div>

templates/default/ldap/macros.html

                     {{ _('Display Name') }}
                 {% endif %}
                 </span></label>
-                <span class="fld-input"><input type="text" name="cn" value="{{value}}" size="35" /></span>
+                <span class="fld-input"><input type="text" name="cn" value="{% if value != 'None' %}{{value}}{% endif %}" size="35" /></span>
             </div>
         </div>
     </fieldset>

templates/default/ldap/user_profile.html

                     <li class="useravatar">{% if jpegPhoto |length != 0 %}<img src="{{ctx.homepath}}/img/{{jpegPhoto.encode('base64')}}" width="120" alt="" />{%else%}{{ _('No avatar available.') }}{%endif%}</li>
                 </ul>
                 <ul class="data-list">
-                    <li class="username fn nickname"><span>{{ _('Display Name') }} <strong>{{cn}}</strong></span></li>
+                    <li class="username fn nickname"><span>{{ _('Display Name') }} <strong>{% if cn != 'None'  %}{{cn}}{% endif %}</strong></span></li>
                     <li><span>{{ _('Mail Address') }} <strong>{{mail}}</strong></span></li>
                     <li><span>{{ _('Employee ID') }} <strong>{{employeeNumber}}</strong></span></li>
                     <li><span>{{ _('Created Date') }} <strong>{{createTimestamp[:4]}}-{{createTimestamp[4:6]}}-{{createTimestamp[6:8]}} {{createTimestamp[8:10]}}:{{createTimestamp[10:12]}}:{{createTimestamp[12:14]}}</strong></span></li>
         <div class="sf-set set1">
             <div class="sf-box text">
                 <label><span>{{ _('Display Name') }}</span></label>
-                <span class="fld-input"><input type="text" name="cn" value="{{cn}}" size="25" /></span>
+                <span class="fld-input"><input type="text" name="cn" value="{% if cn != 'None'  %}{{cn}}{% endif %}" size="25" /></span>
             </div>
             {#
             <div class="sf-box text">