[#77] Use auth_allow_anonymous_access decorator

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
This commit is contained in:
amercader 2014-01-20 13:47:37 +00:00
parent 4cc56f51ab
commit 2b803a3f66
2 changed files with 18 additions and 1 deletions

View File

@ -3,6 +3,19 @@ from ckan.plugins import toolkit as pt
from ckanext.harvest.logic.auth import get_job_object 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): def harvest_source_show(context, data_dict):
''' '''
Authorization check for getting the details of a harvest source Authorization check for getting the details of a harvest source
@ -29,6 +42,7 @@ def harvest_source_show(context, data_dict):
'msg': pt._('User {0} not authorized to read harvest source {1}') 'msg': pt._('User {0} not authorized to read harvest source {1}')
.format(user, source_id)} .format(user, source_id)}
@auth_allow_anonymous_access
def harvest_source_show_status(context, data_dict): def harvest_source_show_status(context, data_dict):
''' '''
Authorization check for getting the status of a harvest source Authorization check for getting the status of a harvest source
@ -37,6 +51,7 @@ def harvest_source_show_status(context, data_dict):
''' '''
return harvest_source_show(context, data_dict) return harvest_source_show(context, data_dict)
@auth_allow_anonymous_access
def harvest_source_list(context, data_dict): def harvest_source_list(context, data_dict):
''' '''
Authorization check for getting a list of harveste sources Authorization check for getting a list of harveste sources
@ -91,6 +106,7 @@ def harvest_job_list(context, data_dict):
@auth_allow_anonymous_access
def harvest_object_show(context, data_dict): def harvest_object_show(context, data_dict):
''' '''
Authorization check for getting the contents of a harvest object Authorization check for getting the contents of a harvest object
@ -107,6 +123,7 @@ def harvest_object_list(context, data_dict):
return {'success': True} return {'success': True}
@auth_allow_anonymous_access
def harvesters_info_show(context, data_dict): def harvesters_info_show(context, data_dict):
''' '''
Authorization check for getting information about the available Authorization check for getting information about the available

View File

@ -84,7 +84,7 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
log.error('Harvest source not found for dataset {0}'.format(data_dict['id'])) log.error('Harvest source not found for dataset {0}'.format(data_dict['id']))
return data_dict 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: 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 # This is a normal dataset, check if it was harvested and if so, add