Skip to content

Commit

Permalink
[ckan#1400] allow overriding dataset, group, org validation
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Dec 18, 2013
1 parent d6ab05b commit 8daf611
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
14 changes: 14 additions & 0 deletions ckan/lib/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from ckan import plugins
import ckan.new_authz

import ckan.lib.navl.dictization_functions.validate as navl_validate

log = logging.getLogger(__name__)

# Mapping from package-type strings to IDatasetForm instances
Expand Down Expand Up @@ -247,6 +249,12 @@ def history_template(self):
def package_form(self):
return 'package/new_package_form.html'

def _validate(self, data_dict, schema, context, action):
"""
Complete control over create/update/show validation.
"""
return navl_validate(data_dict, schema, context)


class DefaultGroupForm(object):
"""
Expand Down Expand Up @@ -420,6 +428,12 @@ def setup_template_variables(self, context, data_dict):
except logic.NotAuthorized:
c.auth_for_change_state = False

def _validate(self, data_dict, schema, context, action):
"""
Complete control over create/update/show validation.
"""
return navl_validate(data_dict, schema, context)


class DefaultOrganizationForm(DefaultGroupForm):
def group_form(self):
Expand Down
6 changes: 4 additions & 2 deletions ckan/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def package_create(context, data_dict):
# to ensure they still work
package_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
data, errors = package_plugin._validate(
data_dict, schema, context, 'create')
log.debug('package_create validate_errs=%r user=%s package=%s data=%r',
errors, context.get('user'),
data.get('name'), data_dict)
Expand Down Expand Up @@ -517,7 +518,8 @@ def _group_or_org_create(context, data_dict, is_org=False):
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
data, errors = group_plugin._validate(
data_dict, schema, context, 'create')
log.debug('group_create validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'), data_dict.get('name'), data_dict)

Expand Down
7 changes: 4 additions & 3 deletions ckan/logic/action/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,8 @@ def package_show(context, data_dict):
else:
schema = package_plugin.show_package_schema()
if schema and context.get('validate', True):
package_dict, errors = _validate(package_dict, schema,
context=context)
package_dict, errors = package_plugin._validate(
package_dict, schema, context, 'show')

for item in plugins.PluginImplementations(plugins.IPackageController):
item.after_show(context, package_dict)
Expand Down Expand Up @@ -1010,7 +1010,8 @@ def _group_or_org_show(context, data_dict, is_org=False):
{'id': group_dict['id']})

if schema:
group_dict, errors = _validate(group_dict, schema, context=context)
group_dict, errors = group_plugin._validate(
group_dict, schema, context, 'show')
return group_dict


Expand Down
6 changes: 4 additions & 2 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def package_update(context, data_dict):
# to ensure they still work.
package_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
data, errors = package_plugin._validate(
data_dict, schema, context, 'update')
log.debug('package_update validate_errs=%r user=%s package=%s data=%r',
errors, context.get('user'),
context.get('package').name if context.get('package') else '',
Expand Down Expand Up @@ -493,7 +494,8 @@ def _group_or_org_update(context, data_dict, is_org=False):
except TypeError:
group_plugin.check_data_dict(data_dict)

data, errors = _validate(data_dict, schema, context)
data, errors = group_plugin._validate(
data_dict, schema, context, 'update')
log.debug('group_update validate_errs=%r user=%s group=%s data_dict=%r',
errors, context.get('user'),
context.get('group').name if context.get('group') else '',
Expand Down

0 comments on commit 8daf611

Please sign in to comment.