Skip to content

Commit

Permalink
Merge pull request #7902 from JVickery-TBS/feature/delete-datastore-t…
Browse files Browse the repository at this point in the history
…able-view

Delete Datastore Table Button (ckanext-datapusher)
  • Loading branch information
kowh-ai committed Nov 14, 2023
2 parents 9c27607 + 1b72ebf commit 7c3d085
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/7902.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds button to delete a Resource's datastore table in ckanext-datapusher
13 changes: 12 additions & 1 deletion ckanext/datapusher/templates/datapusher/resource_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@
{% 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 %}

<form method="post" action="{{ action }}" class="datapusher-form">
<form method="post" action="{{ delete_action }}" class="mb-3 d-inline-block">
{{ h.csrf_input() }}
<button class="btn btn-danger" name="delete" type="submit"
data-module="confirm-action"
data-module-with-data=true
data-module-content="{{ _('Are you sure you want to delete the DataStore and Data Dictionary?') }}">
<i class="fa fa-remove"></i> {{ _('Delete from DataStore') }}
</button>
</form>

<form method="post" action="{{ action }}" class="datapusher-form mb-3 d-inline-block">
{{ h.csrf_input() }}
<button class="btn btn-primary" name="save" type="submit">
<i class="fa fa-cloud-upload"></i> {{ _('Upload to DataStore') }}
Expand Down
26 changes: 26 additions & 0 deletions ckanext/datapusher/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down Expand Up @@ -73,3 +74,28 @@ def get(self, id: str, resource_id: str):
u'/dataset/<id>/resource_data/<resource_id>',
view_func=ResourceDataView.as_view(str(u'resource_data'))
)


@datapusher.route(
"/dataset/<id>/delete-datastore/<resource_id>",
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 and Data Dictionary '
f'deleted for resource {resource_id}'))

return toolkit.h.redirect_to(
'datapusher.resource_data',
id=id,
resource_id=resource_id
)

0 comments on commit 7c3d085

Please sign in to comment.