Commits

Zhang Huangbin  committed 1609fb7

Ability to enable/disable users directly.

  • Participants
  • Parent commits 10db4c1

Comments (0)

Files changed (5)

File controllers/ldap/user.py

         i = web.input(_unicode=False, mail=[])
         self.domain = web.safestr(domain)
         self.mails = i.get('mail', [])
-        result = userLib.delete(domain=self.domain, mails=self.mails)
+        if i.has_key('delete'):
+            result = userLib.delete(domain=self.domain, mails=self.mails,)
+        elif i.has_key('disable'):
+            result = userLib.enableOrDisableAccount(domain=self.domain, mails=self.mails, value='disabled',)
+        elif i.has_key('enable'):
+            result = userLib.enableOrDisableAccount(domain=self.domain, mails=self.mails, value='active',)
         web.seeother('/users/%s' % self.domain)
 
 class profile(dbinit):

File libs/ldaplib/ldaputils.py

     return mod_attrs
 
 def getExceptionDesc(e):
+    if not isinstance(e, tuple):
+        return str(e)
     try:
         msg = ''
         if e.args[0].has_key('info'):
             msg = "%s" % str(e)
         return msg
     except:
-        return "%s " % str(e)
+        return str(e)

File libs/ldaplib/user.py

             return (False, result)
 
     @LDAPDecorators.check_domain_access
+    def enableOrDisableAccount(self, domain, mails, value, attr='accountStatus',):
+        if mails is None or len(mails) == 0: return False
+
+        result = {}
+        for mail in mails:
+            self.mail = web.safestr(mail)
+            self.dn = ldaputils.convEmailToUserDN(self.mail)
+
+            try:
+                self.updateAttrSingleValue(
+                        dn=self.dn,
+                        attr=web.safestr(attr),
+                        value=web.safestr(value),
+                        )
+            except ldap.LDAPError, e:
+                result[self.mail] = str(e)
+
+        if result == {}:
+            return (True, 'SUCCESS')
+        else:
+            return (False, result)
+
+    @LDAPDecorators.check_domain_access
+    def update(self, profile_type, mail, data):
+        self.profile_type = web.safestr(profile_type)
+        self.mail = web.safestr(mail)
+        self.domain = self.mail.split('@', 1)[1]
+        self.dn = ldaputils.convEmailToUserDN(self.mail)
+
+        mod_attrs = []
+        if self.profile_type == 'general':
+            # Get cn.
+    @LDAPDecorators.check_domain_access
     def update(self, profile_type, mail, data):
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)

File templates/default/ldap/layout.html

                 <ul>
                     <li><a href="{{ctx.homepath}}/dashboard">{{ _('Dashboard') }}</a></li>
                     <li><a href="{{ctx.homepath}}/domains">{{ _('Mail Domains') }}</a></li>
+                    <li class="normal"><a href="{{ctx.homepath}}/users">{{ _('Users') }}</a></li>
                     {# Display extra menus for global admin. #}
                     {% if session.get('domainGlobalAdmin') == 'yes' %}
                         <li class="normal"><a href="{{ctx.homepath}}/admins">{{ _('Admins') }}</a></li>
                     {% endif %}
-                    <li class="normal"><a href="{{ctx.homepath}}/users">{{ _('Users') }}</a></li>
                 </ul>
             </div>
 

File templates/default/ldap/users.html

     <div class="frm-buttons">
         <span class="submit">
             <input type="checkbox" id="checkall" />{{ _('Select/Unselect all') }}
-            <input type="submit" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected account(s)?') }}');" }}" />
+            <input type="submit" name="delete" value="{{ _('Delete') }}" onclick="return confirm('{{ _('Are you sure want to delete selected account(s)?') }}');" }}" />
+            <input type="submit" name="disable" value="{{ _('Disable') }}" onclick="return confirm('{{ _('Are you sure want to disable selected account(s)?') }}');" }}" />
+            <input type="submit" name="enable" value="{{ _('Enable') }}" onclick="return confirm('{{ _('Are you sure want to enable selected account(s)?') }}');" }}" />
         </span>
     </div>
+    {% else %}
+        {% block jquery_snippet_sorter %}{% endblock jquery_snippet_sorter %}
     {%endif%}
 </form>
 </div>