From 288e1429a63fe703da719139520cb863d18bc5b2 Mon Sep 17 00:00:00 2001 From: amercader Date: Wed, 9 Jan 2013 17:32:05 +0000 Subject: [PATCH] [#4] Remove the loading of different authorization profiles The different profiles will be now configured via the harvest source datasets on CKAN core, so it is no longer needed. Also simplify IActions and IAuthFunction hook calls. --- ckanext/harvest/plugin.py | 69 ++++++++++----------------------------- 1 file changed, 18 insertions(+), 51 deletions(-) diff --git a/ckanext/harvest/plugin.py b/ckanext/harvest/plugin.py index 3160793..ecd2d19 100644 --- a/ckanext/harvest/plugin.py +++ b/ckanext/harvest/plugin.py @@ -217,58 +217,26 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): p.toolkit.add_template_directory(config, templates) p.toolkit.add_public_directory(config, 'public') - def get_actions(self): - from ckanext.harvest.logic.action.get import (harvest_source_show, - harvest_source_show_status, - harvest_source_list, - harvest_source_for_a_dataset, - harvest_job_show, - harvest_job_list, - harvest_object_show, - harvest_object_list, - harvesters_info_show,) - from ckanext.harvest.logic.action.create import (harvest_source_create, - harvest_job_create, - harvest_job_create_all,) - from ckanext.harvest.logic.action.update import (harvest_source_update, - harvest_objects_import, - harvest_jobs_run) - from ckanext.harvest.logic.action.delete import (harvest_source_delete,) + ## IActions - return { - 'harvest_source_show': harvest_source_show, - 'harvest_source_show_status': harvest_source_show_status, - 'harvest_source_list': harvest_source_list, - 'harvest_source_for_a_dataset': harvest_source_for_a_dataset, - 'harvest_job_show': harvest_job_show, - 'harvest_job_list': harvest_job_list, - 'harvest_object_show': harvest_object_show, - 'harvest_object_list': harvest_object_list, - 'harvesters_info_show': harvesters_info_show, - 'harvest_source_create': harvest_source_create, - 'harvest_job_create': harvest_job_create, - 'harvest_job_create_all': harvest_job_create_all, - 'harvest_source_update': harvest_source_update, - 'harvest_source_delete': harvest_source_delete, - 'harvest_objects_import': harvest_objects_import, - 'harvest_jobs_run':harvest_jobs_run - } + def get_actions(self): + + module_root = 'ckanext.harvest.logic.action' + action_functions = _get_logic_functions(module_root) + + return action_functions + + ## IAuthFunctions def get_auth_functions(self): module_root = 'ckanext.harvest.logic.auth' - auth_profile = config.get('ckan.harvest.auth.profile', '') - - auth_functions = _get_auth_functions(module_root) - if auth_profile: - module_root = '%s.%s' % (module_root, auth_profile) - auth_functions = _get_auth_functions(module_root,auth_functions) - - log.debug('Using auth profile at %s' % module_root) + auth_functions = _get_logic_functions(module_root) return auth_functions ## ITemplateHelpers + def get_helpers(self): from ckanext.harvest import helpers as harvest_helpers return { @@ -279,14 +247,14 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm): } -def _get_auth_functions(module_root, auth_functions = {}): +def _get_logic_functions(module_root, logic_functions = {}): - for auth_module_name in ['get', 'create', 'update','delete']: - module_path = '%s.%s' % (module_root, auth_module_name,) + for module_name in ['get', 'create', 'update','delete']: + module_path = '%s.%s' % (module_root, module_name,) try: module = __import__(module_path) - except ImportError,e: - log.debug('No auth module for action "%s"' % auth_module_name) + except ImportError: + log.debug('No auth module for action "{0}"'.format(module_name)) continue for part in module_path.split('.')[1:]: @@ -294,10 +262,9 @@ def _get_auth_functions(module_root, auth_functions = {}): for key, value in module.__dict__.items(): if not key.startswith('_'): - auth_functions[key] = value + logic_functions[key] = value - - return auth_functions + return logic_functions def _create_harvest_source_object(data_dict): '''