[#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.
This commit is contained in:
amercader 2013-01-09 17:32:05 +00:00
parent 058dcad435
commit 288e1429a6
1 changed files with 18 additions and 51 deletions

View File

@ -217,58 +217,26 @@ class Harvest(p.SingletonPlugin, DefaultDatasetForm):
p.toolkit.add_template_directory(config, templates) p.toolkit.add_template_directory(config, templates)
p.toolkit.add_public_directory(config, 'public') p.toolkit.add_public_directory(config, 'public')
def get_actions(self): ## IActions
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,)
return { def get_actions(self):
'harvest_source_show': harvest_source_show,
'harvest_source_show_status': harvest_source_show_status, module_root = 'ckanext.harvest.logic.action'
'harvest_source_list': harvest_source_list, action_functions = _get_logic_functions(module_root)
'harvest_source_for_a_dataset': harvest_source_for_a_dataset,
'harvest_job_show': harvest_job_show, return action_functions
'harvest_job_list': harvest_job_list,
'harvest_object_show': harvest_object_show, ## IAuthFunctions
'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_auth_functions(self): def get_auth_functions(self):
module_root = 'ckanext.harvest.logic.auth' module_root = 'ckanext.harvest.logic.auth'
auth_profile = config.get('ckan.harvest.auth.profile', '') auth_functions = _get_logic_functions(module_root)
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)
return auth_functions return auth_functions
## ITemplateHelpers ## ITemplateHelpers
def get_helpers(self): def get_helpers(self):
from ckanext.harvest import helpers as harvest_helpers from ckanext.harvest import helpers as harvest_helpers
return { 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']: for module_name in ['get', 'create', 'update','delete']:
module_path = '%s.%s' % (module_root, auth_module_name,) module_path = '%s.%s' % (module_root, module_name,)
try: try:
module = __import__(module_path) module = __import__(module_path)
except ImportError,e: except ImportError:
log.debug('No auth module for action "%s"' % auth_module_name) log.debug('No auth module for action "{0}"'.format(module_name))
continue continue
for part in module_path.split('.')[1:]: 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(): for key, value in module.__dict__.items():
if not key.startswith('_'): if not key.startswith('_'):
auth_functions[key] = value logic_functions[key] = value
return logic_functions
return auth_functions
def _create_harvest_source_object(data_dict): def _create_harvest_source_object(data_dict):
''' '''