Skip to content

Commit

Permalink
Update plugins to comply CKAN 2.9 and 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
blagojabozinovski committed Feb 29, 2024
1 parent 0e2b5a1 commit 0eb829a
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions ckanext/validation/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'] = []
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0eb829a

Please sign in to comment.