Commits

Zhang Huangbin  committed 4d2bd80

Code cleanup.

  • Participants
  • Parent commits a72a741

Comments (0)

Files changed (7)

File controllers/ldap/admin.py

         result = adminLib.add(data=i)
 
         if result[0] is True:
-            web.seeother('/profile/admin/general/%s' % self.mail)
+            web.seeother('/profile/admin/general/%s?msg=CREATE_SUCCESS' % self.mail)
         else:
             self.cn = i.get('cn')
             return render.admin_create(
                 data=i,
                 )
         if result[0] is True:
-            web.seeother('/profile/admin/%s/%s?msg=SUCCESS' % (self.profile_type, self.mail))
+            web.seeother('/profile/admin/%s/%s?msg=UPDATE_SUCCESS' % (self.profile_type, self.mail))
         else:
             if self.profile_type == 'general':
                 return render.admin_profile(

File controllers/ldap/domain.py

     @base.protected
     def GET(self, profile_type, domain):
         i = web.input()
-        domain = web.safestr(domain.split('/', 1)[0])
-        if domain != '' and domain is not None and \
-            profile_type in ['general', 'admins', 'services', 'bcc', 'quotas', 'backupmx', 'advanced', ]:
+        self.domain = web.safestr(domain.split('/', 1)[0])
+        self.profile_type = web.safestr(profile_type)
+        if self.domain == '' or self.domain is None:
+            web.seeother('/domains?msg=EMPTY_DOMAIN')
 
-            domain = web.safestr(domain)
-            profile = domainLib.profile(domain)
+        if self.profile_type not in ['general', 'admins', 'services', 'bcc', 'quotas', 'backupmx', 'advanced', ]:
+            web.seeother('/domains?msg=INCORRECT_PROFILE_TYPE')
 
-            if profile:
-                allDomains = domainLib.list(attrs=['domainName'])
-                allAdmins = adminLib.list()
-                domainAdmins = domainLib.admins(domain)
+        print >> sys.stderr, self.domain
+        result = domainLib.profile(domain=self.domain)
 
-                return render.domain_profile(
-                        cur_domain=domain,
-                        allDomains=allDomains,
-                        profile=profile,
-                        profile_type=profile_type,
-                        admins=allAdmins,
-                        # We need only mail address of domain admins.
-                        domainAdmins=domainAdmins[0][1].get('domainAdmin', []),
-                        msg=i.get('msg', None),
-                        )
-            else:
-                web.seeother('/domains?msg=%s' % i.get('msg', None))
+        if result[0] is True:
+            allDomains = domainLib.list(attrs=['domainName'])
+            allAdmins = adminLib.list()
+            domainAdmins = domainLib.admins(self.domain)
+
+            return render.domain_profile(
+                    cur_domain=self.domain,
+                    allDomains=allDomains,
+                    profile=result[1],
+                    profile_type=self.profile_type,
+                    admins=allAdmins,
+                    # We need only mail address of domain admins.
+                    domainAdmins=domainAdmins[0][1].get('domainAdmin', []),
+                    msg='SUCCESS',
+                    )
         else:
-            web.seeother('/domains?msg=%s' % i.get('msg', None))
+            web.seeother('/domains?msg=%s' % result[1])
 
     @base.protected
     def POST(self, profile_type, domain):

File controllers/ldap/urls.py

 #                 www@example.com, list01@example.com,
 #                 alias01@example.com
 #
-# * Create new accounts:
+# * Create new domain:
 #   - /create/{accountType}
 #
+# * Create new account:
+#   - /create/{accountType}[/domain]
+#
 # * Delete accounts:
 #   - /delete/{accountType}/{account}
 #
 # * List all accounts:
 #   - /domains
 #   - /admins
-#
-# * Show a search form for user to choose domain.
 #   - /users
 #   - /maillists
 #   - /aliases
 #   - /aliases/{domain}
 #
 # * View & Update account profile:
-#   - /profile/{accountType}/{account}
+#   - /profile/{accountType}/{profile_type}/{account}
 #
 
 # Regular expressions.

File libs/ldaplib/domain.py

         else: return False
 
     # Get domain attributes & values.
+    @LDAPDecorators.check_domain_access
     def profile(self, domain):
         self.domain = web.safestr(domain)
-        self.domainDN = ldaputils.convDomainToDN(self.domain)
+        self.dn = ldaputils.convDomainToDN(self.domain)
 
-        # Access control.
-        if self.check_domain_access(self.domainDN, session.get('username')):
-            try:
-                self.domain_detail = self.conn.search_s(
-                        self.domainDN,
-                        ldap.SCOPE_BASE,
-                        '(objectClass=mailDomain)',
-                        attrs.DOMAIN_ATTRS_ALL,
-                        )
-                if len(self.domain_detail) == 1:
-                    return self.domain_detail
-                else:
-                    return False
-            except:
-                return False
-        else:
-            return False
+        try:
+            self.domain_profile = self.conn.search_s(
+                    self.dn,
+                    ldap.SCOPE_BASE,
+                    '(&(objectClass=mailDomain)(domainName=%s))' % self.domain,
+                    attrs.DOMAIN_ATTRS_ALL,
+                    )
+            if len(self.domain_profile) == 1:
+                return (True, self.domain_profile)
+            else:
+                return (False, 'NO_SUCH_DOMAIN')
+        except ldap.NO_SUCH_OBJECT:
+            return (False, 'NO_SUCH_OBJECT')
+        except Exception, e:
+            return (False, str(e))
 
     # Update domain profile.
     # data = web.input()

File libs/ldaplib/user.py

 import ldap, ldap.filter
 import web
 from libs import iredutils
-from libs.ldaplib import core, attrs, ldaputils, deltree
+from libs.ldaplib import core, domain, attrs, ldaputils, deltree
 
 cfg = web.iredconfig
 session = web.config.get('_session')
 LDAPDecorators = core.LDAPDecorators()
 
+domainLib = domain.Domain()
+
 class User(core.LDAPWrap):
     def __del__(self):
         pass

File templates/default/ldap/admin_profile.html

 {# Show message #}
 {% if msg is defined and msg is not sameas none %}
     <div class="ct-box info-box">
-    {% if msg == 'SUCCESS' %}
+    {% if msg == 'CREATE_SUCCESS' %}
+        <div class="success">{{ _('Admin created success.') }}</div>
+    {% elif msg == 'UPDATE_SUCCESS' %}
         <div class="success">{{ _('Profile update success.') }}</div>
     {% else %}
         <div class="error">

File templates/default/ldap/macros.html

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