Commits

Zhang Huangbin  committed 3138777

Fix saving mailQuota issue.
Sync templates.

  • Participants
  • Parent commits f01fbe6

Comments (0)

Files changed (11)

File controllers/ldap/domain.py

     '''List all virtual mail domains.'''
     @base.protected
     def GET(self):
+        i = web.input()
         self.domains = domainLib.list()
-        return render.domains(domains=self.domains)
+        return render.domains(domains=self.domains, msg=i.get('msg', None))
 
     @base.check_global_admin
     @base.protected

File controllers/ldap/user.py

             # List users if only one domain available.
             if isinstance(allDomains, types.ListType) is True and len(allDomains) == 1:
                 cur_domain = str(allDomains[0][1]['domainName'][0])
-                users = userLib.list(domain=cur_domain)
-                if users is not False:
+                result = userLib.list(domain=cur_domain)
+                if result[0] is True:
                     web.seeother('/users/' + cur_domain)
                 else:
-                    web.seeother('/domains?msg=NO_SUCH_DOMAIN')
+                    web.seeother('/domains?msg=%s' % result[1] )
             elif isinstance(allDomains, types.ListType) is True and len(allDomains) == 0:
                 return render.users(msg='NO_DOMAIN_AVAILABLE')
             elif isinstance(allDomains, types.ListType) is True and len(allDomains) > 1:
             else:
                 web.seeother('/domains?msg=NO_SUCH_DOMAIN')
         else:
-            users = userLib.list(domain=domain)
-            if users is not False:
+            result = userLib.list(domain=domain)
+            if result[0] is True:
                 return render.users(
-                        users=users, cur_domain=domain,
+                        users=result[1], cur_domain=domain,
                         allDomains=allDomains,
                         msg=None,
                         )
             else:
-                web.seeother('/domains?msg=NO_SUCH_DOMAIN')
+                web.seeother('/domains?msg=%s' % result[1])
 
     @base.protected
     def POST(self, domain):

File libs/iredbase.py

         )
 
 import iredutils
+render._lookup.filters['filesizeformat'] = iredutils.filesizeformat
 render = iredutils.setRenderLang(render, lang)
 web.render = render

File libs/iredutils.py

 
 cfg = web.iredconfig
 
+def filesizeformat(value, binary=False):
+    """Format the value like a 'human-readable' file size (i.e. 13 KB,
+    4.1 MB, 102 bytes, etc).  Per default decimal prefixes are used (mega,
+    giga etc.), if the second parameter is set to `True` the binary
+    prefixes are (mebi, gibi).
+    """
+    bytes = float(value)
+    base = binary and 1024 or 1000
+    middle = binary and 'i' or ''
+    if bytes < base:
+        return "%d Byte%s" % (bytes, bytes != 1 and 's' or '')
+    elif bytes < base * base:
+        return "%d K%sB" % (bytes / base, middle)
+    elif bytes < base * base * base:
+        return "%d M%sB" % (bytes / (base * base), middle)
+    return "%.1f G%sB" % (bytes / (base * base * base), middle)
+
 def get_translation(lang):
     # Init translations.
     if lang == 'en_US':

File libs/ldaplib/core.py

 
         # Set default size limit.
         #self.conn.set_option(ldap.OPT_SIZELIMIT, int(ldapconf.LDAP_SIZELIMIT))
-        ldap.set_option(ldap.OPT_SIZELIMIT, 100)
-        self.conn.set_option(ldap.OPT_SIZELIMIT, 100)
+        #ldap.set_option(ldap.OPT_SIZELIMIT, 100)
+        #self.conn.set_option(ldap.OPT_SIZELIMIT, 100)
 
         # Set log level.
         #self.conn.set_option(ldap.OPT_DEBUG_LEVEL, int(ldapconf.LDAP_DEBUG_LEVEL))
             return str(e)
 
 class LDAPDecorators(LDAPWrap):
+    def __del__(self):
+        pass
+
     def check_global_admin(self, func):
         def proxyfunc(self, *args, **kw):
             if session.get('domainGlobalAdmin') == 'yes':

File libs/ldaplib/user.py

         self.domain = domain
         self.domainDN = ldaputils.convDomainToDN(self.domain)
 
-        # Check whether user is admin of domain.
-        if self.check_domain_access(self.domainDN, session.get('username')):
-            # Search users under domain.
-            try:
-                self.users = self.conn.search_s(
-                        'ou=Users,' + self.domainDN,
-                        ldap.SCOPE_SUBTREE,
-                        '(objectClass=mailUser)',
-                        attrs.USER_SEARCH_ATTRS,
-                        )
+        try:
+            self.users = self.conn.search_s(
+                    'ou=Users,' + self.domainDN,
+                    ldap.SCOPE_SUBTREE,
+                    '(objectClass=mailUser)',
+                    attrs.USER_SEARCH_ATTRS,
+                    )
+            self.updateAttrSingleValue(self.domainDN, 'domainCurrentUserNumber', len(self.users))
 
-                self.updateAttrSingleValue(self.domainDN, 'domainCurrentUserNumber', len(self.users))
-
-                return self.users
-            except ldap.NO_SUCH_OBJECT:
-                self.conn.add_s(
-                        'ou=Users,'+ self.domainDN,
-                        iredldif.ldif_group('Users'),
-                        )
-                return []
-            except ldap.SIZELIMIT_EXCEEDED:
-                return 'SIZELIMIT_EXCEEDED'
-            except Exception, e:
-                return str(e)
-        else:
-            return False
+            return (True, self.users)
+        except ldap.NO_SUCH_OBJECT:
+            #self.conn.add_s(
+            #        'ou=Users,'+ self.domainDN,
+            #        iredldif.ldif_group('Users'),
+            #        )
+            return (False, 'NO_SUCH_OBJECT')
+        except ldap.SIZELIMIT_EXCEEDED:
+            return (False, 'SIZELIMIT_EXCEEDED')
+        except Exception, e:
+            return (False, str(e))
 
     # Get values of user dn.
     @LDAPDecorators.check_domain_access
             # Get mail address.
 
             # Get mailQuota.
-            mailQuota += web.safestr(data.get('mailQuota', None))
+            mailQuota = web.safestr(data.get('mailQuota', None))
             if mailQuota == '':
                 # Don't touch it, keep old quota value.
                 pass
                 mod_attrs += [ ( ldap.MOD_REPLACE, 'mailQuota', str(int(mailQuota) * 1024 * 1024) ) ]
 
             # Get telephoneNumber.
+            # TODO add multiple value support
             telephoneNumber = data.get('telephoneNumber', [])
-            if telephoneNumber != []:
+            if telephoneNumber != [] and telephoneNumber != [u'']:
                 mod_attrs += [ (ldap.MOD_REPLACE, 'telephoneNumber', None) ]
                 for i in telephoneNumber:
-                    #mod_attrs += [ (ldap.MOD_REPLACE, 'telephoneNumber', str(i)) ]
-                    mod_attrs += [ (ldap.MOD_ADD, 'telephoneNumber', str(i)) ]
+                    mod_attrs += [ ( ldap.MOD_REPLACE, 'telephoneNumber', web.safestr(i) ) ]
 
             # Get accountStatus.
             accountStatus = web.safestr(data.get('accountStatus', 'active'))

File templates/default/ldap/domain_profile.html

 
 {% set createTimestamp = entries.get('createTimestamp', ['--------------'])[0] %}
 
-<form class="frm-form" method="post" method="{{ctx.homepath}}/profile/domain/{{cur_domain}}">
+<form class="frm-form" method="post" action="{{ctx.homepath}}/profile/domain/{{cur_domain}}">
 <div class="main-frm">
     <div class="profile ct-group data-group vcard">
         <div class="ct-set data-set set1">

File templates/default/ldap/domains.html

 
 {% block main %}
 {# Show system message #}
-{#
-{% if msg is not none %}
-    <div class="note">
-        <p>{{ _('System message:') }}</p>
-
-        {{ msg }}
-        <ul>
-        {% for i in msg.items()|sort %}
-            {% if i[1] == 'DELETED' %}
-                <li>{{ _('Deleted:') }} {{ i[0] }}</li>
-            {% elif i[1] == 'NO_SUCH_OBJECT' %}
-                <li>{{ _('No such object:') }} {{ i[0] }}</li>
-            {% else %}
-                <li>{{ i[1] }} {{ i[0] }}</li>
-            {% endif %}
-        {% endfor %}
-        </ul>
+{% if msg is defined and msg is not sameas none %}
+    <div class="ct-box info-box">
+        <div class="error">
+        {% if msg == 'SIZELIMIT_EXCEEDED' %}
+            {{ _('Server-side size limit exceeded.') }}
+        {% elif msg == 'NO_SUCH_OBJECT' %}
+            {{ _('No such domain.') }}
+        {% else %}
+            {# Catch-all #}
+            {{ msg }}
+        {% endif %}
+        </div>
     </div>
 {% endif %}
-#}
 
 {# List all domains under control. #}
 {% if domains is not string and domains |length != 0 %}

File templates/default/ldap/macros.html

     <div class="sf-set {% if firstitem == 'yes' %}set1{% endif %}">
         <div class="sf-box text">
             <label><span>{{ _('Mail quota (in MB)') }}</span></label>
-            <span class="fld-input"><input type="text" name="mailQuota" value="" size="25" />{% if display_current_value == 'yes' %}&nbsp;{{_('Current quota:') }} {% if value == 0 or value == '0' %}<strong>{{ _('Unlimited') }}</strong>{%else%}{{ value |filesizeformat}}&nbsp;({{value}}&nbsp;Bytes){%endif%}{%endif%}</span>
+            <span class="fld-input"><input type="text" name="mailQuota" value="" size="25" />{% if display_current_value == 'yes' %}&nbsp;{{_('Current quota:') }} {% if value == 0 or value == '0' or value == 'None' %}<strong>{{ _('Unlimited') }}</strong>{%else%}{{ value |filesizeformat}}&nbsp;({{value}}&nbsp;Bytes){%endif%}{%endif%}</span>
         </div>
     </div>
 </fieldset>

File templates/default/ldap/preferences.html

             <legend><span>{{ _('Default language') }}</span></legend>
             <div class="sf-box select">
                 <label><span>{{ _('Default language') }}</span></label>
-                <select name="preferredLanguage">
-                    {% for lang in langmaps %}
-                        <option value="{{lang}}" {% if lang == cur_lang %}selected{%endif%}>{{langmaps[lang]}}</option>
-                    {% endfor %}
-                </select>
+                <span class="fld-input">
+                    <select name="preferredLanguage">
+                        {% for lang in langmaps %}
+                            <option value="{{lang}}" {% if lang == cur_lang %}selected{%endif%}>{{langmaps[lang]}}</option>
+                        {% endfor %}
+                    </select>
+                </span>
             </div>
         </fieldset>
 

File templates/default/ldap/user_profile.html

 {% set createTimestamp = entries.get('createTimestamp', ['--------------'])[0] %}
 
 {% if profile_type == 'general' %}
-    {% set telephoneNumber = entries.get('telephoneNumber', ['']) %}
+    {% set telephoneNumber = entries.get('telephoneNumber', []) %}
     {% set accountStatus = entries.get('accountStatus', ['disabled'])[0] %}
     {% set mailQuota = entries.get('mailQuota', [0])[0] %}
 {% endif %}
             <div class="sf-box text">
                 <label><span>{{ _('Telephone Number') }}</span></label>
                 <span class="fld-input">
-                    {% for phone in telephoneNumber %}
-                        <input type="text" name="telephoneNumber_{{loop.index}}" value="{{phone}}" size="25" /><br />
-                    {% endfor %}
+                    {% if telephoneNumber != [] %}
+                        {% for phone in telephoneNumber %}
+                        <input type="text" name="telephoneNumber" value="{{phone}}" size="25" /><br />
+                        {% endfor %}
+                    {% else %}
+                        <input type="text" name="telephoneNumber" value="" size="25" /><br />
+                    {% endif %}
                 </span>
             </div>
         </div>