Skip to content

Commit

Permalink
[#1038] Simplify code that reads ckan.auth config.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Dec 9, 2013
1 parent 22a3432 commit 75394f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions ckan/new_authz.py
Expand Up @@ -379,7 +379,7 @@ def get_user_id_for_username(user_name, allow_none=False):
'user_delete_groups': True,
'user_delete_organizations': True,
'create_user_via_api': False,
'roles_that_cascade_to_sub_groups': ['admin'],
'roles_that_cascade_to_sub_groups': 'admin',
}

CONFIG_PERMISSIONS = {}
Expand All @@ -393,12 +393,14 @@ def check_config_permission(permission):
key = 'ckan.auth.' + perm
default = CONFIG_PERMISSIONS_DEFAULTS[perm]
CONFIG_PERMISSIONS[perm] = config.get(key, default)
if isinstance(default, bool):
CONFIG_PERMISSIONS[perm] = asbool(CONFIG_PERMISSIONS[perm])
elif isinstance(default, list) and key in config:
if perm == 'roles_that_cascade_to_sub_groups':
# this permission is a list of strings (space separated)
CONFIG_PERMISSIONS[perm] = \
CONFIG_PERMISSIONS[perm].split(' ') \
if CONFIG_PERMISSIONS[perm] else []
else:
# most permissions are boolean
CONFIG_PERMISSIONS[perm] = asbool(CONFIG_PERMISSIONS[perm])
if permission in CONFIG_PERMISSIONS:
return CONFIG_PERMISSIONS[permission]
return False
Expand Down
1 change: 0 additions & 1 deletion ckan/tests/test_coding_standards.py
Expand Up @@ -472,7 +472,6 @@ class TestImportStar(object):
'ckan/tests/lib/test_tag_search.py',
'ckan/tests/misc/test_sync.py',
'ckan/tests/models/test_extras.py',
'ckan/tests/models/test_group.py',
'ckan/tests/models/test_misc.py',
'ckan/tests/models/test_package.py',
'ckan/tests/models/test_package_relationships.py',
Expand Down

0 comments on commit 75394f8

Please sign in to comment.