Commits

Zhang Huangbin  committed 8cbdfe2

Fix incorrect decorator for detecting admin privilege.
Fix setting preferred language for new admin.

  • Participants
  • Parent commits c5ff611

Comments (0)

Files changed (7)

File controllers/ldap/admin.py

         self.admins = adminLib.list()
         return render.admins(admins=self.admins)
 
+    # Delete admins.
     @base.check_global_admin
     @base.protected
     def POST(self):
-        i = web.input(dn=[])
-
-        # Post method: add, delete.
-        action = i.get('action', None)
-
-        if action == 'add':
-            # Get admin list (python list obj).
-            admin = i.get('admin', None)
-            passwd = i.get('passwd', None)
-            domainGlobalAdmin = i.get('domainGlobalAdmin', 'no')
-
-            if admin is not None and passwd is not None:
-                # Try to add it.
-                results = self.dbwrap.admin_add(admin, passwd, domainGlobalAdmin)
-
-                # List admins.
-                self.admins = adminLib.list()
-                return render.admins(admins=self.admins, msg=results)
-            else:
-                # Show system message.
-                self.admins = adminLib.list()
-                return render.admins(admins=self.admins, msg='NO_DOMAIN')
-        elif action == 'delete':
-            dn = i.get('dn', [])
-
-            if len(dn) >= 1:
-                # Delete dn(s).
-                results = self.dbwrap.delete_dn(dn)
-
-                # List admins.
-                self.admins = adminLib.list()
-                return render.admins(admins=self.admins, msg=results)
-            else:
-                # Show system message.
-                return render.admins()
-        else:
-            return render.admins()
+        i = web.input(_unicode=False, mail=[])
+        mails = i.mail
+        result = adminLib.delete(mails=mails)
+        web.seeother('/admins')
 
 class create(dbinit):
     @base.check_global_admin

File controllers/ldap/user.py

     @base.protected
     def POST(self, domain):
         i = web.input(_unicode=False, mail=[])
+        self.domain = web.safestr(domain)
         mails = i.mail
-        result = userLib.delete(mails=mails)
-        web.seeother('/users/' + str(domain))
+        result = userLib.delete(domain=self.domain, mails=mails)
+        web.seeother('/users/%s' % self.domain)
 
 class profile(dbinit):
     @base.protected
                     max_passwd_length=cfg.general.get('max_passwd_length'),
                     msg=result[1],
                     )
-
-class delete(dbinit):
-    @base.protected
-    def POST(self):
-        i = web.input(mail=[])
-        domain = i.get('domain', None)
-        if domain is None:
-            web.seeother('/users?msg=NO_DOMAIN')
-
-        mails = i.get('mail', [])
-        for mail in mails:
-            dn = ldap.filter.escape_filter_chars(ldaputils.convEmailToUserDN(mail))
-        web.seeother('/users/' + web.safestr(domain))

File libs/ldaplib/admin.py

         self.cn = data.get('cn')
         self.mail = web.safestr(data.get('username')) + '@' + web.safestr(data.get('domain'))
 
-        self.domainGlobalAdmin = data.get('domainGlobalAdmin', 'yes')
-        if self.domainGlobalAdmin not in ['yes', 'no',]:
-            self.domainGlobalAdmin = 'yes'
+        self.preferredLanguage = web.safestr(data.get('preferredLanguage', 'en_US'))
 
         # Check password.
         self.newpw = web.safestr(data.get('newpw'))
                 mail=self.mail,
                 passwd=self.passwd,
                 cn=self.cn,
-                domainGlobalAdmin=self.domainGlobalAdmin,
+                preferredLanguage=self.preferredLanguage,
                 )
 
         self.dn = ldaputils.convEmailToAdminDN(self.mail)
                 return (True, 'SUCCESS')
             else:
                 return result
+
+    def delete(self):
+        pass

File libs/ldaplib/iredldif.py

     return ldif
 
 # Define and return LDIF structure of domain admin.
-def ldif_mailadmin(mail, passwd, cn, domainGlobalAdmin):
+def ldif_mailadmin(mail, passwd, cn, preferredLanguage='en_US', domainGlobalAdmin='no')
     mail = web.safestr(mail)
 
     ldif = [
             ('mail',            [mail]),
             ('userPassword',    [str(passwd)]),
             ('accountStatus',   ['active']),
-            ('domainGlobalAdmin',   [str(domainGlobalAdmin)]),
+            ('preferredLanguage', [web.safestr(preferredLanguage)]),
+            ('domainGlobalAdmin',   [web.safestr(domainGlobalAdmin)]),
             ]
 
     if cn is not None and cn != '':

File libs/ldaplib/user.py

         except Exception, e:
             return (False, str(e))
 
-    @LDAPDecorators.check_global_admin
-    def delete(self, mails=[]):
+    @LDAPDecorators.check_domain_access
+    def delete(self, domain, mails=[]):
         if mails is None or len(mails) == 0: return False
 
-        msg = {}
+        result = {}
         for mail in mails:
             self.mail = web.safestr(mail)
             dn = ldaputils.convEmailToUserDN(self.mail)
             try:
                 deltree.DelTree( self.conn, dn, ldap.SCOPE_SUBTREE )
             except ldap.LDAPError, e:
-                msg[self.mail] = str(e)
+                result[self.mail] = str(e)
 
-        if msg == {}: return True
-        else: return False
+        if result == {}:
+            return (True, 'SUCCESS')
+        else:
+            return (False, result)
 
     @LDAPDecorators.check_domain_access
     def update(self, profile_type, mail, data):

File templates/default/ldap/admin_create.html

         </div>
     </fieldset>
 
-    {{ display_preferredLanguage(
-            languagemaps=languagemaps)
-            }}
+    {{ display_preferredLanguage(languagemaps=languagemaps) }}
 
     {{ display_reset_password(firstitem='no') }}
 

File templates/default/ldap/macros.html

 {% macro display_preferredLanguage(value='', languagemaps=['en_US',], firstitem='yes') -%}
     <fieldset class="frm-group {% if firstitem == 'yes' %}group1{% endif %}">
         <div class="sf-set {% if firstitem == 'yes' %}set1{% endif %}">
-            <div class="sf-box text">
+            <div class="sf-box select">
                 <label><span>{{ _('Default language') }}</span></label>
                 <span class="fld-input">
                     <select name="preferredLanguage">
 {%- endmacro %}
 
 {# Display accountStatus #}
-{% macro display_account_status(accountStatus) %}
-    <fieldset class="frm-group">
-        <legend class="group-legend"><strong>{{ _('Account status') }}</strong></legend>
+{% macro display_account_status(accountStatus, firstitem='yes') %}
+    <fieldset class="frm-group {% if firstitem == 'yes' %}group1{% endif %}">
+        <fieldset class="mf-set required {% if firstitem == 'yes' %}set1{% endif %}">
         <fieldset class="mf-set required">
             <legend><span>{{ _('Account status') }}<em>{{ _('(Required)') }}</em></span></legend>
             <div class="mf-box">