Commits

Zhang Huangbin committed 58de55c

Fix update domain profile.

  • Participants
  • Parent commits 3138777

Comments (0)

Files changed (3)

controllers/ldap/domain.py

 class profile(dbinit):
     @base.protected
     def GET(self, 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', ]:
                         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=NO_SUCH_DOMAIN')
+                web.seeother('/domains?msg=%s' % i.get('msg', None))
         else:
-            web.seeother('/domains?msg=NO_SUCH_DOMAIN')
+            web.seeother('/domains?msg=%s' % i.get('msg', None))
 
     @base.protected
-    def POST(self, domain):
+    def POST(self, profile_type, domain):
+        self.profile_type = web.safestr(profile_type)
+        self.domain = web.safestr(domain)
+
         i = web.input(enabledService=[],)
-        self.result = domainLib.update(data=i)
-        if self.result:
-            web.seeother('/profile/domain/' + web.safestr(domain) + '?msg=SUCCESS')
-        else:
-            web.seeother('/profile/domain/' + web.safestr(domain))
+
+        result = domainLib.update(
+                profile_type=self.profile_type,
+                domain=self.domain,
+                data=i,
+                )
+        if result[0] is True:
+            web.seeother('/profile/domain/%s/%s?msg=SUCCESS' % (self.profile_type, self.domain) )
+        elif result[0] is False:
+            web.seeother('/profile/domain/%s/%s?msg=%s' % (self.profile_type, self.domain, result[1]) )
 
 class create(dbinit):
     @base.check_global_admin

libs/ldaplib/domain.py

 
     # Update domain profile.
     # data = web.input()
-    def update(self, data):
-        domain = web.safestr(data.get('domainName'))
-        cn = data.get('cn', None)
+    def update(self, profile_type, domain, data):
+        self.profile_type = web.safestr(profile_type)
+        self.domain = web.safestr(domain)
 
-        if cn is not None:
-            mod_attrs = [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
-        else:
-            # Delete attribute.
-            mod_attrs = [ ( ldap.MOD_DELETE, 'cn', None) ]
+        mod_attrs = []
+        if self.profile_type == 'general':
+            cn = data.get('cn', None)
+            if cn is not None:
+                mod_attrs += [ ( ldap.MOD_REPLACE, 'cn', cn.encode('utf-8') ) ]
+            else:
+                # Delete attribute.
+                mod_attrs += [ ( ldap.MOD_DELETE, 'cn', None) ]
 
         if session.get('domainGlobalAdmin') == 'yes':
             # Convert to string, they don't contain non-ascii characters.
             pass
 
         try:
-            dn = ldaputils.convDomainToDN(domain)
+            dn = ldaputils.convDomainToDN(self.domain)
             self.conn.modify_s(dn, mod_attrs)
-            return True
+            return (True, 'SUCCESS')
         except Exception, e:
-            return False
+            return (False, str(e))

templates/default/ldap/domain_profile.html

 
 {# Domain profile. #}
 {% block main %}
+
+{# message #}
+{% if msg is defined and msg is not sameas none %}
+    <div class="ct-box info-box">
+        {% if msg == 'SUCCESS' %}
+        <div class="success">
+            {{ _('Profile update success.') }}
+        </div>
+        {% else %}
+            {# Password #}
+            {% if profile_type == 'password' %}
+            <div class="error">
+                {{msg}}
+            </div>
+            {% else %}
+            {# Catch-all #}
+            <div class="error">
+                {{ msg }}
+            </div>
+            {% endif %}
+        {% endif %}
+    </div>
+{% endif %}
+
 {% set p = profile[0] %}
 {% set dn = p[0] %}
 {% set entries = p[1] %}
 
 {% set createTimestamp = entries.get('createTimestamp', ['--------------'])[0] %}
 
-<form class="frm-form" method="post" action="{{ctx.homepath}}/profile/domain/{{cur_domain}}">
+<form class="frm-form" method="post" action="{{ctx.homepath}}/profile/{{profile_type}}/{{cur_domain}}">
 <div class="main-frm">
     <div class="profile ct-group data-group vcard">
         <div class="ct-set data-set set1">