1. Zhang Huangbin
  2. iredadmin-ose

Commits

Zhang Huangbin  committed bf272b7

Code cleanup.

  • Participants
  • Parent commits fe6a539
  • Branches default

Comments (0)

Files changed (8)

File ChangLog

View file
 = 0.2 =
+    * Show employee id while list users.
     * Ability to modify user's employee id (employeeNumber).
+    * Fix issue while submit empty display name (cn).
 
 = 0.1 =
     * Initiaize release.

File libs/ldaplib/admin.py

View file
             mod_attrs += [ (ldap.MOD_REPLACE, 'preferredLanguage', self.lang) ]
 
             cn = data.get('cn', None)
-            mod_attrs += ldaputils.getModAttrCN(cn, default=self.mail.split('@')[0])
+            mod_attrs += ldaputils.getSingleModAttr(attr='cn', value='cn', default=self.mail.split('@')[0])
 
             try:
                 # Modify profiles.

File libs/ldaplib/attrs.py

View file
 
 USER_SEARCH_ATTRS = [
         # Required attributes.
-        'mail', 'cn', 'accountStatus', 'mailQuota', 'jpegPhoto',
+        'mail', 'cn', 'accountStatus', 'mailQuota', 'employeeNumber',
         'createTimestamp',                      # Internal/System attributes.
         ]
 

File libs/ldaplib/domain.py

View file
         mod_attrs = []
         if self.profile_type == 'general':
             cn = data.get('cn', None)
-            mod_attrs += ldaputils.getModAttrCN(cn, default=self.domain)
+            mod_attrs += ldaputils.getSingleModAttr(attr='cn', value=cn, default=self.domain)
 
         if session.get('domainGlobalAdmin') == 'yes':
             accountStatus = web.safestr(data.get('accountStatus', 'active'))

File libs/ldaplib/iredldif.py

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

File libs/ldaplib/ldaputils.py

View file
 
     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') ) ]
+def getSingleModAttr(attr, value, default='None'):
+    if value is not None and value != '' and value != u'':
+        mod_attrs = [ ( ldap.MOD_REPLACE, attr, value.encode('utf-8') ) ]
     else:
         # Value is 'None' (string, not NoneType).
-        mod_attrs = [ ( ldap.MOD_REPLACE, 'cn', default ) ]
+        mod_attrs = [ ( ldap.MOD_REPLACE, attr, default ) ]
 
     return mod_attrs

File libs/ldaplib/user.py

View file
         if self.profile_type == 'general':
             # Get cn.
             cn = data.get('cn', None)
-            mod_attrs += ldaputils.getModAttrCN(cn, default=self.mail.split('@')[0])
+            mod_attrs += ldaputils.getSingleModAttr(attr='cn', value=cn, default=self.mail.split('@')[0])
 
             # Get mail address.
 
 
             # Get telephoneNumber.
             employeeNumber = web.safestr(data.get('employeeNumber', 'None'))
-            mod_attrs += [ ( ldap.MOD_REPLACE, 'employeeNumber', employeeNumber ) ]
+            mod_attrs += ldaputils.getSingleModAttr(attr='employeeNumber', value=employeeNumber, default='None')
             
             # TODO add multiple value support
             telephoneNumber = data.get('telephoneNumber', [])

File templates/default/ldap/users.html

View file
         <tr>
             <th>{{ _('Mail Address') }}</th>
             <th>{{ _('Display Name') }}</th>
+            <th>{{ _('Employee ID') }}</th>
             <th>{{ _('Quota') }}</th>
             <th>{{ _('Created Date') }}</th>
         </tr>
                 {% set entries = i[1] %}
                 {% set mail = entries.get('mail')[0] |string %}
                 {% set cn = entries.get('cn', [''])[0].decode('utf-8') %}
+                {% set employeeid = entries.get('employeeNumber', [''])[0].decode('utf-8') %}
                 {# If not present, mark as 'disabled'. #}
                 {% set accountStatus = entries.get('accountStatus', ['disabled'])[0] %} 
                 {% set createTimestamp = entries.get('createTimestamp', ['--------------'])[0] %}
                         <span class="float_right">{{ set_account_status_img(accountStatus) }}</span>
                     </td>
                     <td><a href="{{ctx.homepath}}/profile/user/general/{{mail}}" title="{{ _('Edit user profile') }}">{{ cn }}</a></td>
+                    <td>{{ employeeid }}</a></td>
 
                 {# mail quota #}
                 <td>{% if entries.get('mailQuota', ['0'])[0] == '0' %}{{ _('Unlimited') }}{% else %}{{ entries.get('mailQuota', ['0'])[0] |filesizeformat }} {% endif %}</td>