Skip to content

Commit

Permalink
[#669] Fix member_list call when given valid group name.
Browse files Browse the repository at this point in the history
Now returns lists of (id, type, capacity) tuples
where type is a string. Previously, type was a
Python class object which could not always be
serialized to JSON in the API controller.
  • Loading branch information
johnglover committed Mar 20, 2013
1 parent fc51d0e commit 077f71a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 2 additions & 12 deletions ckan/logic/action/get.py
Expand Up @@ -277,25 +277,15 @@ def member_list(context, data_dict=None):
if capacity:
q = q.filter(model.Member.capacity == capacity)

lookup = {}
def type_lookup(name):
if name in lookup:
return lookup[name]
if hasattr(model, name.title()):
lookup[name] = getattr(model,name.title())
return lookup[name]
return None

trans = new_authz.roles_trans()

def translated_capacity(capacity):
try:
return trans[capacity]
except KeyError:
return capacity

return [(m.table_id,
type_lookup(m.table_name),
translated_capacity(m.capacity),)
return [(m.table_id, m.table_name, translated_capacity(m.capacity))
for m in q.all()]

def _group_or_org_list(context, data_dict, is_org=False):
Expand Down
3 changes: 3 additions & 0 deletions ckan/tests/logic/test_member.py
Expand Up @@ -46,6 +46,8 @@ def test_member_list(self):
ctx, dd = self._build_context('','package')
res = get_action('member_list')(ctx,dd)
assert len(res) == 2, res
assert (self.pkgs[0].id, 'package', 'public') in res
assert (self.pkgs[1].id, 'package', 'public') in res

ctx, dd = self._build_context('','user', 'admin')
res = get_action('member_list')(ctx,dd)
Expand All @@ -55,6 +57,7 @@ def test_member_list(self):
ctx, dd = self._build_context('','user', 'admin')
res = get_action('member_list')(ctx,dd)
assert len(res) == 1, res
assert (self.username, 'user', 'Admin') in res


def test_member_delete(self):
Expand Down

0 comments on commit 077f71a

Please sign in to comment.