From 1b663bbff4f29a1e34144447755f38585f190bbb Mon Sep 17 00:00:00 2001 From: joetsoi Date: Wed, 4 Sep 2013 14:17:01 +0100 Subject: [PATCH] add harvest_object_create action --- ckanext/harvest/logic/action/create.py | 21 +++++++++++++++++++-- ckanext/harvest/logic/auth/create.py | 10 ++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ckanext/harvest/logic/action/create.py b/ckanext/harvest/logic/action/create.py index 392ac48..7e0e059 100644 --- a/ckanext/harvest/logic/action/create.py +++ b/ckanext/harvest/logic/action/create.py @@ -6,8 +6,9 @@ from ckan.logic import NotFound, check_access from ckanext.harvest.logic import HarvestJobExists from ckanext.harvest.plugin import DATASET_TYPE_NAME -from ckanext.harvest.model import (HarvestSource, HarvestJob) -from ckanext.harvest.logic.dictization import harvest_job_dictize +from ckanext.harvest.model import (HarvestSource, HarvestJob, HarvestObject) +from ckanext.harvest.logic.dictization import (harvest_job_dictize, + harvest_object_dictize) from ckanext.harvest.logic.schema import harvest_source_show_package_schema from ckanext.harvest.logic.action.get import harvest_source_list,harvest_job_list @@ -136,3 +137,19 @@ def _check_for_existing_jobs(context, source_id): exist = len(exist_new + exist_running) > 0 return exist + +def harvest_object_create(context, data_dict): + check_access('harvest_object_create', context, data_dict) + + job_id = data_dict['job_id'] + + job = HarvestJob.get(job_id) + if not job: + log.warn('Harvest job %s does not exist', job_id) + raise NotFound('Harvest job %s does not exist' % job_id) + + guid = data_dict['guid'] + content = data_dict.get('content', '') + + obj = HarvestObject(guid=guid, content=content, job=job) + return harvest_object_dictize(obj, context) diff --git a/ckanext/harvest/logic/auth/create.py b/ckanext/harvest/logic/auth/create.py index 03aa01b..953f2d4 100644 --- a/ckanext/harvest/logic/auth/create.py +++ b/ckanext/harvest/logic/auth/create.py @@ -52,3 +52,13 @@ def harvest_job_create_all(context, data_dict): return {'success': False, 'msg': pt._('Only sysadmins can create harvest jobs for all sources')} else: return {'success': True} + +def harvest_object_create(context, data_dict): + """ + Auth check for creating a harvest object + + only the sysadmins can create harvest objects + """ + # sysadmins can run all actions if we've got to this point we're not a sysadmin + return {'success': False, 'msg': pt._('Only the sysadmins can create harvest objects')} +