ckan / ckan/ckanext-validation

Custom upload endpoints

Open
#81 0 comments 0 reactions 0 assignees View on GitHub
Schema Editor
Dominant language
Python
Stars
30
Forks
33
PR merge metrics
No merged PRs in 30d

Description

High-level spec: https://github.com/frictionlessdata/ckanext-validation/issues/65#issuecomment-1335093859

Update the ckanext-validation blueprint to include:

1. An endpoint that accepts an uploaded file or a URL and creates a resource with a file (POST `/dataset//resource/file`). This will be used when in step 1 of creating a new resource (uploading the file). This endpoint will:
* Do some [data processing](https://github.com/ckan/ckan/blob/c37dcb3aa861e302fcc21a36c9e9babbb183527e/ckan/views/resource.py#L189) and call `resource_create` with the `package_id` and the `upload` / `url` fields
* Decide if this resource is a tabular one, and if so detect the schema calling `resource_table_schema_infer` (see https://github.com/frictionlessdata/ckanext-validation/issues/76)
* Return the dataset id, the resource id and the inferred table schema description if present

2. An endpoint that accepts an uploaded file or a URL and updates the file of resource (POST `/dataset//resource//file`). This will be used when updating an existing resource. This endpoint will:
* Do some [data processing](https://github.com/ckan/ckan/blob/c37dcb3aa861e302fcc21a36c9e9babbb183527e/ckan/views/resource.py#L189) and call `resource_patch` with the `resource_id` and the `upload` / `url` fields
* Decide if this resource is a tabular one, and if so detect the schema calling `resource_table_schema_infer` (see https://github.com/frictionlessdata/ckanext-validation/issues/76)
* Return the dataset id, the resource id and the inferred table schema description if present

Additional endpoints:

* Do we need a custom endpoint for step 2 of creating a new resource (clicking "Save")? The standard resource create endpoint (POST `/dataset//new`) seems to support [updating an existing resource](https://github.com/ckan/ckan/blob/c37dcb3aa861e302fcc21a36c9e9babbb183527e/ckan/views/resource.py#L250) if a resource id is provided so that might work out of the box. We just need to make sure client-side that the resource_id is set after getting the response from step 1 (and that the file is not submitted again). That would cover the "Finish" and "Save and Add another" buttons
* What happens if a user hits "Previous" or leaves the page after uploading a file? CKAN does not have a concept of "draft resources" so I think we just need to delete the resource:
* For the "Previous" rather than overriding the whole core `/dataset/resource/new` endpoint, I think it will be easier to have a custom endpoint (POST `/dataset//resource/cancel`) that accepts a resource_id (which we'll have if we have uploaded a file) and deletes the resource and the file. If there is no resource_id we just submit the default endpoint.
* If the user leaves the page without having clicked on "Finish" we can maybe rely on [`beforeunload`](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event) to fire a request to the previous endpoint?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.