Commits

Zhang Huangbin committed 56fcda6

Show users marked as admin in admin list page.

Comments (0)

Files changed (6)

controllers/mysql/admin.py

 
 import web
 from libs import languages, iredutils
-from libs.mysql import decorators, admin as adminlib, domain as domainlib, connUtils
+from libs.mysql import decorators, admin as adminlib, domain as domainlib
 
 cfg = web.iredconfig
 session = web.config.get('_session')
         adminLib = adminlib.Admin()
         result = adminLib.listAccounts(cur_page=cur_page)
         if result[0] is True:
-            (total, records) = (result[1], result[2])
+            (total, records) = (result[1]['total'], result[1]['records'])
 
             return web.render(
                 'mysql/admin/list.html',

controllers/pgsql/admin.py

 
 import web
 from libs import languages, iredutils
-from libs.pgsql import decorators, admin as adminlib, domain as domainlib, connUtils
+from libs.pgsql import decorators, admin as adminlib, domain as domainlib
 
 cfg = web.iredconfig
 session = web.config.get('_session')
         adminLib = adminlib.Admin()
         result = adminLib.listAccounts(cur_page=cur_page)
         if result[0] is True:
-            (total, records) = (result[1], result[2])
+            (total, records) = (result[1]['total'], result[1]['records'])
 
             return web.render(
                 'pgsql/admin/list.html',
             # Get managed domains.
             self.managedDomains = []
 
-            connutils = connUtils.Utils()
-            qr = connutils.getManagedDomains(admin=self.mail, domainNameOnly=True, listedOnly=True,)
-            if qr[0] is True:
-                self.managedDomains += qr[1]
-
             return web.render(
                 'pgsql/admin/profile.html',
                 mail=self.mail,
                 profile=profile,
                 languagemaps=languages.getLanguageMaps(),
                 allDomains=self.allDomains,
-                managedDomains=self.managedDomains,
                 min_passwd_length=cfg.general.get('min_passwd_length', '0'),
                 max_passwd_length=cfg.general.get('max_passwd_length', '0'),
                 msg=i.get('msg'),
             )
 
         try:
-            result = self.conn.select('admin', what='COUNT(username) AS total')
-            if len(result) > 0:
-                total = result[0].total or 0
-        except Exception:
-            pass
+            # Get number of total accounts
+            # Separate admin accounts
+            admins_total = self.conn.select('admin', what='COUNT(username) AS total')
+            if admins_total:
+                admins_total = admins_total[0].total or 0
 
-        try:
-            result = self.conn.query(
+            # Users marked as admin
+            useradmins_total = self.conn.select(
+                'mailbox',
+                what='COUNT(username) AS total',
+                where='isadmin=1',
+            )
+            if useradmins_total:
+                useradmins_total = useradmins_total[0].total or 0
+
+            total = admins_total + useradmins_total
+
+            # Get records
+            # Separate admins
+            admins_records = self.conn.query(
                 """
                 SELECT name, username, language, active
                 FROM admin
                 %s
                 """ % (self.sql_limit)
             )
-            return (True, total, list(result))
+
+            useradmins_records = self.conn.query(
+                """
+                SELECT name, username, language, active, isadmin, isglobaladmin
+                FROM mailbox
+                ORDER BY username ASC
+                %s
+                """ % (self.sql_limit)
+            )
+            return (True, {'total': total, 'records': list(admins_records) + list(useradmins_records)})
         except Exception, e:
             return (False, str(e))
 
             )
 
         try:
-            result = self.conn.select('admin', what='COUNT(username) AS total')
-            if len(result) > 0:
-                total = result[0].total or 0
-        except Exception:
-            pass
+            # Get number of total accounts
+            # Separate admin accounts
+            admins_total = self.conn.select('admin', what='COUNT(username) AS total')
+            if admins_total:
+                admins_total = admins_total[0].total or 0
 
-        try:
-            result = self.conn.query(
+            # Users marked as admin
+            useradmins_total = self.conn.select(
+                'mailbox',
+                what='COUNT(username) AS total',
+                where='isadmin=1',
+            )
+            if useradmins_total:
+                useradmins_total = useradmins_total[0].total or 0
+
+            total = admins_total + useradmins_total
+
+            # Get records
+            # Separate admins
+            admins_records = self.conn.query(
                 """
                 SELECT name, username, language, active
                 FROM admin
                 %s
                 """ % (self.sql_limit)
             )
-            return (True, total, list(result))
+
+            useradmins_records = self.conn.query(
+                """
+                SELECT name, username, language, active, isadmin, isglobaladmin
+                FROM mailbox
+                ORDER BY username ASC
+                %s
+                """ % (self.sql_limit)
+            )
+            return (True, {'total': total, 'records': list(admins_records) + list(useradmins_records)})
         except Exception, e:
             return (False, str(e))
 

templates/default/mysql/admin/list.html

                 <tr>
                     <td class="checkbox"><input type="checkbox" name="mail" value="{{ username }}" {% if username == session.get('username') %}disabled{% endif %}/></td>
                     <td>
-                        <a href="{{ctx.homepath}}/profile/admin/general/{{ username }}"><img src="{{ctx.homepath}}/static/{{skin}}/images/action_edit.png" title="{{ _('Edit account profile') }}" class="fr-space"/></a>
+                        <a href="{{ctx.homepath}}/profile/{% if r.get('isadmin') is not sameas none %}user{% else %}admin{% endif %}/general/{{ username }}"><img src="{{ctx.homepath}}/static/{{skin}}/images/action_edit.png" title="{{ _('Edit account profile') }}" class="fr-space"/></a>
                         {{ set_account_status_img(r.active) }}
 
                         {# -- Show name -- #}
                         {% endif %}
                     </td>
                     <td>{{ username }}</td>
-                    <td>{{ set_admin_type_img('yes') }}</td>
+                    {% if r.get('isglobaladmin') is not sameas none %}
+                        {# users marked as admin #}
+                        {% if r.get('isglobaladmin') == 1 %}
+                            <td>{{ set_admin_type_img('yes') }}</td>
+                        {% else %}
+                            <td>{{ set_admin_type_img('no') }}</td>
+                        {% endif %}
+                    {% else %}
+                        {# Separate admin accounts #}
+                        {% if username in allGlobalAdmins %}
+                            <td>{{ set_admin_type_img('yes') }}</td>
+                        {% else %}
+                            <td>{{ set_admin_type_img('no') }}</td>
+                        {% endif %}
+                    {% endif %}
                 </tr>
             {% endfor %}
         </tbody>

templates/default/pgsql/admin/list.html

                 <tr>
                     <td class="checkbox"><input type="checkbox" name="mail" value="{{ username }}" {% if username == session.get('username') %}disabled{% endif %}/></td>
                     <td>
-                        <a href="{{ctx.homepath}}/profile/admin/general/{{ username }}"><img src="{{ctx.homepath}}/static/{{skin}}/images/action_edit.png" title="{{ _('Edit account profile') }}" class="fr-space"/></a>
+                        <a href="{{ctx.homepath}}/profile/{% if r.get('isadmin') is not sameas none %}user{% else %}admin{% endif %}/general/{{ username }}"><img src="{{ctx.homepath}}/static/{{skin}}/images/action_edit.png" title="{{ _('Edit account profile') }}" class="fr-space"/></a>
                         {{ set_account_status_img(r.active) }}
 
                         {# -- Show name -- #}
                         {% endif %}
                     </td>
                     <td>{{ username }}</td>
-                    <td>{{ set_admin_type_img('yes') }}</td>
+                    {% if r.get('isglobaladmin') is not sameas none %}
+                        {# users marked as admin #}
+                        {% if r.get('isglobaladmin') == 1 %}
+                            <td>{{ set_admin_type_img('yes') }}</td>
+                        {% else %}
+                            <td>{{ set_admin_type_img('no') }}</td>
+                        {% endif %}
+                    {% else %}
+                        {# Separate admin accounts #}
+                        {% if username in allGlobalAdmins %}
+                            <td>{{ set_admin_type_img('yes') }}</td>
+                        {% else %}
+                            <td>{{ set_admin_type_img('no') }}</td>
+                        {% endif %}
+                    {% endif %}
                 </tr>
             {% endfor %}
         </tbody>