Skip to content

Commit

Permalink
[ckan#77] Use auth_allow_anonymous_access decorator
Browse files Browse the repository at this point in the history
Starting from 2.2 you need to explicitly flag auth functions that
allow anonymous access with the p.toolkit.auth_allow_anonymous_access
decorator. A local version of the decorator is used to ensure we only
use it on CKAN>=2.2
  • Loading branch information
amercader committed Jan 20, 2014
1 parent 4cc56f5 commit 2b803a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions ckanext/harvest/logic/auth/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
from ckanext.harvest.logic.auth import get_job_object



def auth_allow_anonymous_access(auth_function):
'''
Local version of the auth_allow_anonymous_access decorator that only
calls the actual toolkit decorator if the CKAN version supports it
'''
if pt.check_ckan_version(min_version='2.2'):
auth_function = pt.auth_allow_anonymous_access(auth_function)

return auth_function


@auth_allow_anonymous_access
def harvest_source_show(context, data_dict):
'''
Authorization check for getting the details of a harvest source
Expand All @@ -29,6 +42,7 @@ def harvest_source_show(context, data_dict):
'msg': pt._('User {0} not authorized to read harvest source {1}')
.format(user, source_id)}

@auth_allow_anonymous_access
def harvest_source_show_status(context, data_dict):
'''
Authorization check for getting the status of a harvest source
Expand All @@ -37,6 +51,7 @@ def harvest_source_show_status(context, data_dict):
'''
return harvest_source_show(context, data_dict)

@auth_allow_anonymous_access
def harvest_source_list(context, data_dict):
'''
Authorization check for getting a list of harveste sources
Expand Down Expand Up @@ -91,6 +106,7 @@ def harvest_job_list(context, data_dict):



@auth_allow_anonymous_access
def harvest_object_show(context, data_dict):
'''
Authorization check for getting the contents of a harvest object
Expand All @@ -107,6 +123,7 @@ def harvest_object_list(context, data_dict):
return {'success': True}


@auth_allow_anonymous_access
def harvesters_info_show(context, data_dict):
'''
Authorization check for getting information about the available
Expand Down
2 changes: 1 addition & 1 deletion ckanext/harvest/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def after_show(self, context, data_dict):
log.error('Harvest source not found for dataset {0}'.format(data_dict['id']))
return data_dict

data_dict['status'] = harvest_logic.action.get.harvest_source_show_status(context, {'id': source.id})
data_dict['status'] = p.toolkit.get_action('harvest_source_show_status')(context, {'id': source.id})

elif not 'type' in data_dict or data_dict['type'] != DATASET_TYPE_NAME:
# This is a normal dataset, check if it was harvested and if so, add
Expand Down

0 comments on commit 2b803a3

Please sign in to comment.