Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Extension Support #200

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f0a470a
feat(dev): adds validation extension support;
JVickery-TBS Nov 24, 2023
a97f4ad
feat(dev): logging;
JVickery-TBS Nov 24, 2023
028e42b
fix(dev): 2.9 support;
JVickery-TBS Nov 24, 2023
77d762e
fix(dev): better conditioning;
JVickery-TBS Nov 27, 2023
aec22b9
feat(comments): added comments;
JVickery-TBS Nov 27, 2023
cd3c7cc
Merge branch 'master' into feature/validation-support
JVickery-TBS Jan 29, 2024
7e99aa7
fix(dev): misc feedback;
JVickery-TBS Jan 29, 2024
25ea76e
fix(dev): misc fixes;
JVickery-TBS Jan 29, 2024
d2720fc
fix(syntax): flake8;
JVickery-TBS Jan 31, 2024
e888153
feat(dev): logic and schema config option;
JVickery-TBS Feb 2, 2024
5c07ba4
Merge branch 'master' into feature/validation-support
JVickery-TBS Feb 2, 2024
4612484
feat(dev): better logic and tests;
JVickery-TBS Feb 2, 2024
8ac8db5
fix(logic): fixed some logic;
JVickery-TBS Feb 2, 2024
d9bb56c
Merge branch 'master' into feature/validation-support
JVickery-TBS Feb 5, 2024
1ac8090
fix(syntax): made better;
JVickery-TBS Feb 5, 2024
1761ed5
fix(comments): fixed inline comments;
JVickery-TBS Feb 5, 2024
e182eb7
feat(dev): started doing sync mode;
JVickery-TBS Feb 6, 2024
b386e0e
feat(dev): sync mode cont.;
JVickery-TBS Feb 7, 2024
3200483
feat(dev): sync mode cont.;
JVickery-TBS Feb 7, 2024
d225801
Merge branch 'master' into feature/validation-support
JVickery-TBS May 16, 2024
4fbdb0d
feat(dev): IPipeValidation implementation;
JVickery-TBS May 16, 2024
27d98cf
fix(tests): validation req tests;
JVickery-TBS May 16, 2024
378f69f
fix(misc): comments and messages;
JVickery-TBS Jul 12, 2024
6070740
fix(logic): ignore not sysadmin;
JVickery-TBS Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ckanext/xloader/config_declaration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,13 @@ groups:
to True.
type: bool
required: false
- key: ckanext.xloader.requires_validation
default: False
example: True
description: |
Resources are required to pass validation from the ckanext-validation
plugin to be able to get xloadered.
type: bool
required: false


36 changes: 34 additions & 2 deletions ckanext/xloader/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,23 @@ def notify(self, entity, operation):
See: ckan/model/modification.py.DomainObjectModificationExtension
"""
if operation != DomainObjectOperation.changed \
or not isinstance(entity, Resource) \
or not getattr(entity, 'url_changed', False):
or not isinstance(entity, Resource):
return

# If the resource requires validation, stop here if validation
# has not been performed or did not succeed. The Validation
# extension will call resource_patch and this method should
# be called again. However, url_changed will not be in the entity
# once Validation does the patch.
if _is_validation_plugin_loaded() and \
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')):
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
if entity.__dict__.get('extras', {}).get('validation_status', None) != 'success':
JVickery-TBS marked this conversation as resolved.
Show resolved Hide resolved
log.debug("Skipping xloading resource %s because "
"resource did not pass validation yet.", entity.id)
return
elif not getattr(entity, 'url_changed', False):
return

context = {
"ignore_auth": True,
}
Expand All @@ -124,6 +138,12 @@ def notify(self, entity, operation):
# IResourceController

def after_resource_create(self, context, resource_dict):
if _is_validation_plugin_loaded() and \
toolkit.asbool(toolkit.config.get('ckanext.xloader.requires_validation')) and \
resource_dict.get('validation_status', None) != 'success':
log.debug("Skipping xloading resource %s because "
"resource did not pass validation yet.", resource_dict.get('id'))
return
self._submit_to_xloader(resource_dict)

def before_resource_show(self, resource_dict):
Expand Down Expand Up @@ -225,3 +245,15 @@ def get_helpers(self):
"xloader_status": xloader_helpers.xloader_status,
"xloader_status_description": xloader_helpers.xloader_status_description,
}


def _is_validation_plugin_loaded():
"""
Checks the existence of a logic action from the ckanext-validation
plugin, thus supporting any extending of the Validation Plugin class.
"""
try:
toolkit.get_action('resource_validation_show')
return True
except KeyError:
return False
Loading