Commits

Zhang Huangbin committed 4cf962e

Code cleanup.

Comments (0)

Files changed (7)

controllers/ldap/user.py

 class profile(dbinit):
     @base.protected
     def GET(self, profile_type, mail):
-        i = web.input(enabledService=[], telephoneNumber=[],)
+        i = web.input(enabledService=[],telephoneNumber=[],mailForwardingAddress=[],)
         self.mail = web.safestr(mail)
         self.profile_type = web.safestr(profile_type)
 
 
     @base.protected
     def POST(self, profile_type, mail):
-        i = web.input(enabledService=[], telephoneNumber=[],)
+        i = web.input(enabledService=[],telephoneNumber=[],mailForwardingAddress=[],)
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)
 

libs/ldaplib/admin.py

                     )
             return (True, self.admin_profile)
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     def add(self, data):
         self.cn = data.get('cn')
         except ldap.ALREADY_EXISTS:
             return (False, 'ALREADY_EXISTS')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     # Update admin profile.
     # data: must be a webpy storage object.
                     session['lang'] = self.lang
                 return (True, 'SUCCESS')
             except ldap.LDAPError, e:
-                return (False, str(e))
+                return (False, ldaputils.getExceptionDesc(e))
 
         if self.profile_type == 'password':
             self.cur_passwd = data.get('cur_passwd', None)

libs/ldaplib/core.py

         except ldap.UNWILLING_TO_PERFORM:
             return (False, 'INCORRECT_OLDPW')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     def check_domain_exist(self, domainName):
         self.result = self.conn.search_s(

libs/ldaplib/domain.py

         except ldap.NO_SUCH_OBJECT:
             return (False, 'NO_SUCH_OBJECT')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     # Update domain profile.
     # data = web.input()
             self.conn.modify_s(dn, mod_attrs)
             return (True, 'SUCCESS')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))

libs/ldaplib/ldaputils.py

         mod_attrs = [ ( ldap.MOD_REPLACE, attr, default ) ]
 
     return mod_attrs
+
+def getExceptionDesc(e):
+    try:
+        msg = ''
+        if e.args[0].has_key('info'):
+            # Get attribute name.
+            msg += e.args[0]['info'].split(':')[0]
+        if e.args[0].has_key('desc'):
+            # Get error description.
+            msg += ': ' + e.args[0]['desc']
+        else:
+            msg = "%s" % str(e)
+        return msg
+    except:
+        return "%s " % str(e)

libs/ldaplib/user.py

         except ldap.SIZELIMIT_EXCEEDED:
             return (False, 'SIZELIMIT_EXCEEDED')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     # Get values of user dn.
     @LDAPDecorators.check_domain_access
         except ldap.ALREADY_EXISTS:
             return (False, 'ALREADY_EXISTS')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))
 
     @LDAPDecorators.check_domain_access
     def delete(self, domain, mails=[]):
             
             # TODO add multiple value support
             telephoneNumber = data.get('telephoneNumber', [])
-            if telephoneNumber != [] and telephoneNumber != [u'']:
+            if telephoneNumber != [] and telephoneNumber != [u''] and telephoneNumber != []:
                 mod_attrs += [ (ldap.MOD_REPLACE, 'telephoneNumber', None) ]
                 for i in telephoneNumber:
                     mod_attrs += [ ( ldap.MOD_REPLACE, 'telephoneNumber', web.safestr(i) ) ]
             self.conn.modify_s(dn, mod_attrs)
             return (True, 'SUCCESS')
         except Exception, e:
-            return (False, str(e))
+            return (False, ldaputils.getExceptionDesc(e))

templates/default/ldap/domains.html

         <div class="error">
         {% if msg == 'SIZELIMIT_EXCEEDED' %}
             {{ _('Server-side size limit exceeded.') }}
+        {% elif msg == 'PERMISSION_DENIED' %}
+            {{ _('Permission denied.') }}
         {% elif msg == 'NO_SUCH_OBJECT' %}
             {{ _('No such domain.') }}
         {% else %}