From 0eb829a443cf97e4a6760a20bc3f9f0972cb116d Mon Sep 17 00:00:00 2001 From: blagoja Date: Thu, 29 Feb 2024 19:28:20 +0100 Subject: [PATCH] Update plugins to comply CKAN 2.9 and 2.10 --- ckanext/validation/logic.py | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/ckanext/validation/logic.py b/ckanext/validation/logic.py index 213e4648..8bc6d31b 100644 --- a/ckanext/validation/logic.py +++ b/ckanext/validation/logic.py @@ -24,6 +24,8 @@ log = logging.getLogger(__name__) +ckan_2_10 = t.check_ckan_version(min_version="2.10") + def enqueue_job(*args, **kwargs): try: @@ -448,9 +450,14 @@ def resource_create(up_func, context, data_dict): {'id': package_id}) t.check_access('resource_create', context, data_dict) - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.before_create(context, data_dict) + + # Check if CKAN version is min 2.10 + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_resource_create(context, data_dict) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_create(context, data_dict) if 'resources' not in pkg_dict: pkg_dict['resources'] = [] @@ -519,9 +526,13 @@ def resource_create(up_func, context, data_dict): {'resource': resource, 'package': updated_pkg_dict }) - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.after_create(context, resource) + + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_resource_create(context, resource) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_create(context, resource) return resource @@ -575,9 +586,13 @@ def resource_update(up_func, context, data_dict): if ('datastore_active' in resource.extras and 'datastore_active' not in data_dict): data_dict['datastore_active'] = resource.extras['datastore_active'] - - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.before_update(context, pkg_dict['resources'][n], data_dict) + + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_resource_update(context, pkg_dict['resources'][n], data_dict) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.before_update(context, pkg_dict['resources'][n], data_dict) upload = uploader.get_resource_uploader(data_dict) @@ -636,8 +651,12 @@ def resource_update(up_func, context, data_dict): {'package': updated_pkg_dict, 'resource': resource}) - for plugin in plugins.PluginImplementations(plugins.IResourceController): - plugin.after_update(context, resource) + if ckan_2_10: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_resource_update(context, resource) + else: + for plugin in plugins.PluginImplementations(plugins.IResourceController): + plugin.after_update(context, resource) return resource