From 9c5be60ee49159f86c2f3518ed2f17a1623450cf Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Mon, 24 Jul 2023 19:10:54 +0000 Subject: [PATCH 1/3] fix(validation): only allow uploads to go through validation code; - Implemented `IDataValidation` and `can_validate` method. --- ckanext/canada/plugins.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ckanext/canada/plugins.py b/ckanext/canada/plugins.py index 330d4b7fc..527f372f6 100755 --- a/ckanext/canada/plugins.py +++ b/ckanext/canada/plugins.py @@ -21,6 +21,7 @@ from ckanext.canada import helpers from ckanext.canada import activity as act from ckanext.extendedactivity.plugins import IActivity +from ckanext.validation.interfaces import IDataValidation import json @@ -49,6 +50,7 @@ class DataGCCAInternal(p.SingletonPlugin): p.implements(p.IPackageController, inherit=True) p.implements(p.IActions) p.implements(p.IResourceUrlChange) + p.implements(IDataValidation) def update_config(self, config): p.toolkit.add_template_directory(config, 'templates/internal') @@ -232,6 +234,16 @@ def get_actions(self): resource_view_create=resource_view_create_bilingual, ) + # IDataValidation + + def can_validate(self, context, resource): + """ + Only uploaded resources are allowed to be validated + """ + if resource.get(u'url_type') != u'upload': + return False + return True + @chained_action From 75baa582b5ce376a06af9edb699d2afe1c2209df Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Mon, 24 Jul 2023 19:37:58 +0000 Subject: [PATCH 2/3] fix(dev): moved import; - Moved validation ext import into Internal plugin class. --- ckanext/canada/plugins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ckanext/canada/plugins.py b/ckanext/canada/plugins.py index 527f372f6..b8e0e4b80 100755 --- a/ckanext/canada/plugins.py +++ b/ckanext/canada/plugins.py @@ -21,7 +21,6 @@ from ckanext.canada import helpers from ckanext.canada import activity as act from ckanext.extendedactivity.plugins import IActivity -from ckanext.validation.interfaces import IDataValidation import json @@ -50,7 +49,8 @@ class DataGCCAInternal(p.SingletonPlugin): p.implements(p.IPackageController, inherit=True) p.implements(p.IActions) p.implements(p.IResourceUrlChange) - p.implements(IDataValidation) + from ckanext.validation.interfaces import IDataValidation + p.implements(IDataValidation, inherit=True) def update_config(self, config): p.toolkit.add_template_directory(config, 'templates/internal') From 931137c1ce8daa071a6a13d3d076ae0e6ebf01cb Mon Sep 17 00:00:00 2001 From: Jesse Vickery <97247789+JVickery-TBS@users.noreply.github.com> Date: Mon, 24 Jul 2023 16:07:20 -0400 Subject: [PATCH 3/3] Update ckanext/canada/plugins.py Co-authored-by: Ian Ward --- ckanext/canada/plugins.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ckanext/canada/plugins.py b/ckanext/canada/plugins.py index b8e0e4b80..31ec85c78 100755 --- a/ckanext/canada/plugins.py +++ b/ckanext/canada/plugins.py @@ -49,8 +49,12 @@ class DataGCCAInternal(p.SingletonPlugin): p.implements(p.IPackageController, inherit=True) p.implements(p.IActions) p.implements(p.IResourceUrlChange) - from ckanext.validation.interfaces import IDataValidation - p.implements(IDataValidation, inherit=True) + try: + from ckanext.validation.interfaces import IDataValidation + except ImportError: + log.warn('failed to import ckanext-validation interface') + else: + p.implements(IDataValidation, inherit=True) def update_config(self, config): p.toolkit.add_template_directory(config, 'templates/internal')