Skip to content

Commit

Permalink
[#2939] Fix group/org delete permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Nov 19, 2012
1 parent c236148 commit f114c2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ckan/logic/auth/delete.py
Expand Up @@ -74,22 +74,29 @@ def package_relationship_delete(context, data_dict):
def group_delete(context, data_dict):
group = get_group_object(context, data_dict)
user = context['user']
if not new_authz.check_config_permission('user_delete_groups'):
return {'success': False,
'msg': _('User %s not authorized to delete groups') % user}
authorized = new_authz.has_user_permission_for_group_or_org(
group.id, user, 'delete')
if not authorized:
return {'success': False, 'msg': _('User %s not authorized to delete group %s') % (str(user),group.id)}
return {'success': False, 'msg': _('User %s not authorized to delete group %s') % (user ,group.id)}
else:
return {'success': True}

def organization_delete(context, data_dict):
group = get_group_object(context, data_dict)
user = context['user']
if not new_authz.check_config_permission('user_delete_organizations'):
return {'success': False,
'msg': _('User %s not authorized to delete organizations') % user}
authorized = new_authz.has_user_permission_for_group_or_org(
group.id, user, 'delete')
if not authorized:
return {'success': False, 'msg': _('User %s not authorized to delete organization %s') % (str(user),group.id)}
return {'success': False, 'msg': _('User %s not authorized to delete organization %s') % (user ,group.id)}
else:
return {'success': True}

def revision_undelete(context, data_dict):
return {'success': False, 'msg': 'Not implemented yet in the auth refactor'}

Expand Down
2 changes: 2 additions & 0 deletions ckan/new_authz.py
Expand Up @@ -233,6 +233,8 @@ def _get_auth_function(action, profile=None):
'create_unowned_dataset': True,
'user_create_groups': True,
'user_create_organizations': True,
'user_delete_groups': True,
'user_delete_organizations': True,
'create_user_via_api': False,
}

Expand Down
2 changes: 2 additions & 0 deletions ckan/tests/logic/test_auth.py
Expand Up @@ -10,6 +10,8 @@
'create_dataset_if_not_in_organization': False,
'user_create_groups': False,
'user_create_organizations': False,
'user_delete_groups': False,
'user_delete_organizations': False,
'create_user_via_api': False,
'create_unowned_dataset': False,
}
Expand Down

0 comments on commit f114c2d

Please sign in to comment.