Skip to content

Commit

Permalink
Merge branch '1393-bug-user-create-returns-email-for-api-key'
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Dec 16, 2013
2 parents 6213f0d + 9a2840b commit 4a89b78
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
18 changes: 2 additions & 16 deletions ckan/lib/dictization/model_dictize.py
Expand Up @@ -525,13 +525,13 @@ def user_dictize(user, context):
result_dict['email'] = email

if context.get('keep_apikey', False):
result_dict['apikey'] = email
result_dict['apikey'] = apikey

if requester == user.name:
result_dict['apikey'] = apikey
result_dict['email'] = email

## this should not really really be needed but tests r it
## this should not really really be needed but tests need it
if new_authz.is_sysadmin(requester):
result_dict['apikey'] = apikey
result_dict['email'] = email
Expand Down Expand Up @@ -708,17 +708,3 @@ def user_following_group_dictize(follower, context):

base_columns = set(['id', 'resource_id', 'title', 'description',
'view_type', 'order', 'config'])

def resource_view_dictize(resource_view, context):
dictized = d.table_dictize(resource_view, context)
dictized.pop('order')
config = dictized.pop('config', {})
dictized.update(config)
return dictized

def resource_view_list_dictize(resource_views, context):
resource_view_dicts = []
for view in resource_views:
resource_view_dicts.append(resource_view_dictize(view, context))
return resource_view_dicts

41 changes: 41 additions & 0 deletions ckan/new_tests/logic/action/test_get.py
Expand Up @@ -147,6 +147,47 @@ def test_organization_show_private_packages_not_returned(self):
assert org_dict['packages'][0]['name'] == 'dataset_1'
assert org_dict['package_count'] == 1

def test_user_get(self):

user = factories.User()

## auth_ignored
got_user = helpers.call_action('user_show', id=user['id'])

assert 'password' not in got_user
assert 'reset_key' not in got_user
assert 'apikey' not in got_user
assert 'email' not in got_user

got_user = helpers.call_action('user_show',
context={'keep_email': True},
id=user['id'])

assert got_user['email'] == user['email']
assert 'apikey' not in got_user
assert 'password' not in got_user
assert 'reset_key' not in got_user

got_user = helpers.call_action('user_show',
context={'keep_apikey': True},
id=user['id'])

assert 'email' not in got_user
assert got_user['apikey'] == user['apikey']
assert 'password' not in got_user
assert 'reset_key' not in got_user

sysadmin = factories.User(sysadmin=True)

got_user = helpers.call_action('user_show',
context={'user': sysadmin['name']},
id=user['id'])

assert got_user['email'] == user['email']
assert got_user['apikey'] == user['apikey']
assert 'password' not in got_user
assert 'reset_key' not in got_user


class TestBadLimitQueryParameters(object):
'''test class for #1258 non-int query parameters cause 500 errors
Expand Down

0 comments on commit 4a89b78

Please sign in to comment.