Skip to content

Commit

Permalink
[#1664] package_create+update: fix config permission check
Browse files Browse the repository at this point in the history
Use the same permission checks for both package_update and package_create
and check all the applicable config options: anon_create_dataset,
create_unowned_dataset and create_dataset_if_not_in_organization
  • Loading branch information
wardi committed Apr 23, 2014
1 parent f1d8838 commit 9ea722e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
14 changes: 10 additions & 4 deletions ckan/logic/auth/create.py
Expand Up @@ -9,11 +9,17 @@ def package_create(context, data_dict=None):
user = context['user']

if new_authz.auth_is_anon_user(context):
check1 = new_authz.check_config_permission('anon_create_dataset')
check1 = all(new_authz.check_config_permission(p) for p in (
'anon_create_dataset',
'create_dataset_if_not_in_organization',
'create_unowned_dataset',
))
else:
check1 = new_authz.check_config_permission('create_dataset_if_not_in_organization') \
or new_authz.check_config_permission('create_unowned_dataset') \
or new_authz.has_user_permission_for_some_org(user, 'create_dataset')
check1 = all(new_authz.check_config_permission(p) for p in (
'create_dataset_if_not_in_organization',
'create_unowned_dataset',
)) or new_authz.has_user_permission_for_some_org(
user, 'create_dataset')

if not check1:
return {'success': False, 'msg': _('User %s not authorized to create packages') % user}
Expand Down
15 changes: 11 additions & 4 deletions ckan/logic/auth/update.py
Expand Up @@ -23,11 +23,18 @@ def package_update(context, data_dict):
)
else:
# If dataset is not owned then we can edit if config permissions allow
if not new_authz.auth_is_anon_user(context):
check1 = new_authz.check_config_permission(
'create_dataset_if_not_in_organization')
if new_authz.auth_is_anon_user(context):
check1 = all(new_authz.check_config_permission(p) for p in (
'anon_create_dataset',
'create_dataset_if_not_in_organization',
'create_unowned_dataset',
))
else:
check1 = new_authz.check_config_permission('anon_create_dataset')
check1 = all(new_authz.check_config_permission(p) for p in (
'create_dataset_if_not_in_organization',
'create_unowned_dataset',
)) or new_authz.has_user_permission_for_some_org(
user, 'create_dataset')
if not check1:
return {'success': False,
'msg': _('User %s not authorized to edit package %s') %
Expand Down

0 comments on commit 9ea722e

Please sign in to comment.