add user access list
add user access list

file:a/.gitignore -> file:b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,36 @@
-*.pyc
+*.py[cod]
 
+# C extensions
+*.so
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+lib
+lib64
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+nosetests.xml
+
+# Translations
+*.mo
+
+# Mr Developer
+.mr.developer.cfg
+.project
+.pydevproject
+

file:a/ckanext/__init__.pyc (deleted)
 Binary files a/ckanext/__init__.pyc and /dev/null differ
 Binary files a/ckanext/dga_stats/__init__.pyc and /dev/null differ
--- a/ckanext/dga_stats/controller.py
+++ b/ckanext/dga_stats/controller.py
@@ -17,6 +17,7 @@
         c.summary_stats = stats.summary_stats()
         c.activity_counts = stats.activity_counts()
         c.by_org = stats.by_org()
+        c.user_access_list = stats.user_access_list()
         c.new_packages_by_week = rev_stats.get_by_week('new_packages')
         c.deleted_packages_by_week = rev_stats.get_by_week('deleted_packages')
         c.num_packages_by_week = rev_stats.get_num_packages_by_week()

 Binary files a/ckanext/dga_stats/controller.pyc and /dev/null differ
 Binary files a/ckanext/dga_stats/plugin.pyc and /dev/null differ
--- a/ckanext/dga_stats/stats.py
+++ b/ckanext/dga_stats/stats.py
@@ -122,7 +122,6 @@
     @classmethod
     def summary_stats(cls):
        connection = model.Session.connection()
-#				select name,role from user_object_role inner join \"user\" on user_object_role.user_id = \"user\".id where name not in ('logged_in','visitor') group by name,role"
 
        res = connection.execute("SELECT 'Total Organisations', count(*) from \"group\" where type = 'organization' and state = 'active' union \
 				select 'Total Datasets', count(*) from package where state='active' or state='draft' or state='draft-complete' union \
@@ -134,6 +133,12 @@
     def activity_counts(cls):
        connection = model.Session.connection()
        res = connection.execute("select to_char(timestamp, 'YYYY-MM') as month,activity_type, count(*) from activity group by month, activity_type order by month;").fetchall();
+       return res
+
+    @classmethod
+    def user_access_list(cls):
+       connection = model.Session.connection()
+       res = connection.execute("select name,sysadmin,role from user_object_role right outer join \"user\" on user_object_role.user_id = \"user\".id where name not in ('logged_in','visitor') group by name,sysadmin,role order by sysadmin desc, role asc;").fetchall();
        return res
 
 

 Binary files a/ckanext/dga_stats/stats.pyc and /dev/null differ
--- a/ckanext/dga_stats/templates/ckanext/stats/index.html
+++ b/ckanext/dga_stats/templates/ckanext/stats/index.html
@@ -54,7 +54,33 @@
         <p class="empty">{{ _('No groups') }}</p>
       {% endif %}
     </section>
-
+{% if h.check_access('sysadmin') %}
+    <section id="user-access-list" class="module-content tab-content">
+      <h2>{{ _('User Access List') }}</h2>
+      {% if c.user_access_list %}
+        <table class="table table-chunky table-bordered table-striped">
+          <thead>
+            <tr>
+              <th>{{ _('Username') }}</th>
+              <th>{{ _('Sysadmin') }}</th>
+              <th class="metric">{{ _('Organisational Role') }}</th>
+            </tr>
+          </thead>
+          <tbody>
+            {% for username,sysadmin,role in c.user_access_list %}
+              <tr>
+                <td>{{ username }}</td>
+                <td>{{ sysadmin }}</td>
+                <td>{{ role }}</td>
+              </tr>
+            {% endfor %}
+          </tbody>
+        </table>
+      {% else %}
+        <p class="empty">{{ _('No groups') }}</p>
+      {% endif %}
+    </section>
+{% endif %}
     <section id="stats-total-datasets" class="module-content tab-content active">
       <h2>{{ _('Total number of Datasets') }}</h2>
 
@@ -254,9 +280,12 @@
     <h2 class="module-heading"><i class="icon-bar-chart icon-medium"></i> {{ _('Statistics Menu') }}</h2>
     <nav data-module="stats-nav">
       <ul class="unstyled nav nav-simple">
-        <li class="nav-item"><a href="#summary" data-toggle="tab">{{ _('Summary') }}</a></li>
+        <li class="nav-item active"><a href="#summary" data-toggle="tab">{{ _('Summary') }}</a></li>
         <li class="nav-item"><a href="#activity-counts" data-toggle="tab">{{ _('Site Activity Log') }}</a></li>
-        <li class="nav-item active"><a href="#stats-total-datasets" data-toggle="tab">{{ _('Total Number of Datasets') }}</a></li>
+{% if h.check_access('sysadmin') %}
+        <li class="nav-item"><a href="#user-access-list" data-toggle="tab">{{ _('User Access List') }}</a></li>
+{% endif %}
+        <li class="nav-item"><a href="#stats-total-datasets" data-toggle="tab">{{ _('Total Number of Datasets') }}</a></li>
         <li class="nav-item"><a href="#stats-dataset-revisions" data-toggle="tab">{{ _('Dataset Revisions per Week') }}</a></li>
 <!--        <li class="nav-item"><a href="#stats-top-rated" data-toggle="tab">{{ _('Top Rated Datasets') }}</a></li> -->
         <li class="nav-item"><a href="#stats-most-edited" data-toggle="tab">{{ _('Most Edited Datasets') }}</a></li>