diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 342c8c0ef8b..5bfbc1701a7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,15 @@ Changelog --------- +v2.2 +==== + +API changes and deprecations: + +* The edit() and after_update() methods of IPackageController plugins are now + called when updating a resource using the web frontend or the + resource_update API action [#1052] + v2.0.1 2013-06-11 ================= diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index 9917e6893f4..889bfe5ad4e 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -207,31 +207,26 @@ def resource_update(context, data_dict): raise NotFound(_('Resource was not found.')) _check_access('resource_update', context, data_dict) + del context["resource"] - if 'schema' in context: - schema = context['schema'] - else: - package_plugin = lib_plugins.lookup_package_plugin( - resource.resource_group.package.type) - schema = package_plugin.update_package_schema()['resources'] + package_id = resource.resource_group.package.id + pkg_dict = _get_action('package_show')(context, {'id': package_id}) - data, errors = _validate(data_dict, schema, context) - if errors: - model.Session.rollback() - raise ValidationError(errors) - - rev = model.repo.new_revision() - rev.author = user - if 'message' in context: - rev.message = context['message'] + for n, p in enumerate(pkg_dict['resources']): + if p['id'] == id: + break else: - rev.message = _(u'REST API: Update object %s') % data.get("name", "") + logging.error('Could not find resource ' + id) + raise NotFound(_('Resource was not found.')) + pkg_dict['resources'][n] = data_dict - resource = model_save.resource_dict_save(data, context) - if not context.get('defer_commit'): - model.repo.commit() - return model_dictize.resource_dictize(resource, context) + try: + pkg_dict = _get_action('package_update')(context, pkg_dict) + except ValidationError, e: + errors = e.error_dict['resources'][n] + raise ValidationError(errors) + return pkg_dict['resources'][n] def package_update(context, data_dict): diff --git a/ckan/tests/logic/test_action.py b/ckan/tests/logic/test_action.py index 6a5d4600e10..46655c5b621 100644 --- a/ckan/tests/logic/test_action.py +++ b/ckan/tests/logic/test_action.py @@ -684,10 +684,11 @@ def test_19_update_resource(self): resource_updated.pop('url') resource_updated.pop('revision_id') + resource_updated.pop('revision_timestamp') resource_created.pop('url') resource_created.pop('revision_id') resource_created.pop('revision_timestamp') - assert resource_updated == resource_created + assert_equal(resource_updated, resource_created) def test_20_task_status_update(self): package_created = self._add_basic_package(u'test_task_status_update')