From c37a6b212dd8771ad4f513d23c70d6d4924881e9 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 8 Nov 2023 20:20:21 +0000 Subject: [PATCH 1/3] feat(views): added view and button to delete ds table; - Added view to delete datastore table. - Added button to delete a resource's datastore table. --- .../templates/datapusher/resource_data.html | 17 +++++++++--- ckanext/datapusher/views.py | 26 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ckanext/datapusher/templates/datapusher/resource_data.html b/ckanext/datapusher/templates/datapusher/resource_data.html index d8928d3e9d4..482bf24855c 100644 --- a/ckanext/datapusher/templates/datapusher/resource_data.html +++ b/ckanext/datapusher/templates/datapusher/resource_data.html @@ -5,10 +5,21 @@ {% block primary_content_inner %} {% set action = h.url_for('datapusher.resource_data', id=pkg.name, resource_id=res.id) %} + {% set delete_action = h.url_for('datapusher.delete_datastore_table', id=pkg.id, resource_id=res.id) %} {% set show_table = true %} -
- {{ h.csrf_input() }} + + {{ h.csrf_input() }} + +
+ +
+ {{ h.csrf_input() }} @@ -76,7 +87,7 @@

{{ _('Upload Log') }}

{% endfor %} {{ h.time_ago_from_timestamp(item.timestamp) }} - + {{ _('Details') }} diff --git a/ckanext/datapusher/views.py b/ckanext/datapusher/views.py index 650189b861d..0404c7ed808 100644 --- a/ckanext/datapusher/views.py +++ b/ckanext/datapusher/views.py @@ -7,6 +7,7 @@ import ckan.logic as logic import ckan.lib.helpers as core_helpers import ckan.lib.base as base +from ckan.types import Context, Response from ckan.common import _ @@ -73,3 +74,28 @@ def get(self, id: str, resource_id: str): u'/dataset//resource_data/', view_func=ResourceDataView.as_view(str(u'resource_data')) ) + + +@datapusher.route( + "/dataset//delete-datastore-table/", + methods=["POST"] +) +def delete_datastore_table(id: str, resource_id: str) -> Response: + context: Context = {"user": toolkit.current_user.name} + + try: + toolkit.get_action('datastore_delete')( + context, {'resource_id': resource_id, 'force': True}) + except toolkit.NotAuthorized: + return toolkit.abort( + 403, _(f'Unauthorized to delete resource {resource_id}')) + + toolkit.h.flash_notice( + _('DataStore table and Data Dictionary ' + f'deleted for resource {resource_id}')) + + return toolkit.h.redirect_to( + 'datapusher.resource_data', + id=id, + resource_id=resource_id + ) From c0b0014255f4bea70c981092d52e00ede0d093c5 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Wed, 8 Nov 2023 20:26:20 +0000 Subject: [PATCH 2/3] feat(dev): added changelog; - Added change log file. --- changes/7902.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/7902.feature diff --git a/changes/7902.feature b/changes/7902.feature new file mode 100644 index 00000000000..4008739278b --- /dev/null +++ b/changes/7902.feature @@ -0,0 +1 @@ +Adds button to delete a Resource's datastore table in ckanext-datapusher From 1f9c78ea3b9907d7215f5672ad28bb513dfb80f3 Mon Sep 17 00:00:00 2001 From: Jesse Vickery Date: Thu, 9 Nov 2023 15:02:01 +0000 Subject: [PATCH 3/3] fix(semantics): removed word table; - Removed the word table from user visual things. --- ckanext/datapusher/templates/datapusher/resource_data.html | 4 ++-- ckanext/datapusher/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ckanext/datapusher/templates/datapusher/resource_data.html b/ckanext/datapusher/templates/datapusher/resource_data.html index 482bf24855c..ada76824093 100644 --- a/ckanext/datapusher/templates/datapusher/resource_data.html +++ b/ckanext/datapusher/templates/datapusher/resource_data.html @@ -13,8 +13,8 @@ diff --git a/ckanext/datapusher/views.py b/ckanext/datapusher/views.py index 0404c7ed808..38a3304071f 100644 --- a/ckanext/datapusher/views.py +++ b/ckanext/datapusher/views.py @@ -77,7 +77,7 @@ def get(self, id: str, resource_id: str): @datapusher.route( - "/dataset//delete-datastore-table/", + "/dataset//delete-datastore/", methods=["POST"] ) def delete_datastore_table(id: str, resource_id: str) -> Response: @@ -91,7 +91,7 @@ def delete_datastore_table(id: str, resource_id: str) -> Response: 403, _(f'Unauthorized to delete resource {resource_id}')) toolkit.h.flash_notice( - _('DataStore table and Data Dictionary ' + _('DataStore and Data Dictionary ' f'deleted for resource {resource_id}')) return toolkit.h.redirect_to(