[ckan-changes] commit/ckan: dread: [cli]: Added fix to viewing sysadmins - you would get an exception when one of them was an authorization group.

Bitbucket commits-noreply at bitbucket.org
Tue Jul 5 16:03:33 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/a7fba765129e/
changeset:   a7fba765129e
user:        dread
date:        2011-07-05 18:02:53
summary:     [cli]: Added fix to viewing sysadmins - you would get an exception when one of them was an authorization group.
affected #:  1 file (389 bytes)

--- a/ckan/lib/cli.py	Tue Jul 05 12:14:52 2011 +0100
+++ b/ckan/lib/cli.py	Tue Jul 05 17:02:53 2011 +0100
@@ -298,7 +298,7 @@
     '''Gives sysadmin rights to a named user
 
     Usage:
-      sysadmin list                 - lists sysadmins
+      sysadmin list (default)       - lists sysadmins
       sysadmin add <user-name>      - add a user as a sysadmin
       sysadmin remove <user-name>   - removes user from sysadmins
     '''
@@ -306,14 +306,14 @@
     summary = __doc__.split('\n')[0]
     usage = __doc__
     max_args = 2
-    min_args = 1
+    min_args = 0
 
     def command(self):
         self._load_config()
         from ckan import model
 
-        cmd = self.args[0]
-        if cmd == 'list':
+        cmd = self.args[0] if self.args else None
+        if cmd == None or cmd == 'list':
             self.list()
         elif cmd == 'add':
             self.add()
@@ -325,9 +325,14 @@
     def list(self):
         from ckan import model
         print 'Sysadmins:'
-        sysadmins = model.Session.query(model.SystemRole).filter_by(role=model.Role.ADMIN).all()
+        sysadmins = model.Session.query(model.SystemRole).filter_by(role=model.Role.ADMIN)
+        print 'count = %i' % sysadmins.count()
         for sysadmin in sysadmins:
-            print 'name=%s id=%s' % (sysadmin.user.name, sysadmin.user.id)
+            user_or_authgroup = sysadmin.user or sysadmin.authorized_group
+            assert user_or_authgroup, 'Could not extract entity with this priviledge from: %r' % sysadmin
+            print '%s name=%s id=%s' % (user_or_authgroup.__class__.__name__,
+                                        user_or_authgroup.name,
+                                        user_or_authgroup.id)
 
     def add(self):
         from ckan import model

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list