Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to master - handle 'delete all' without JavaScript #96

Merged
merged 9 commits into from
Oct 26, 2023
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
run: bin/test.sh
timeout-minutes: 20

- name: Retrieve logs
if: always()
run: ahoy logs
timeout-minutes: 5

- name: Retrieve screenshots
if: failure()
run: bin/process-artifacts.sh
Expand Down
20 changes: 13 additions & 7 deletions ckanext/datarequests/controllers/controller_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,17 @@ def purge(user_id):
data_dict = {'user_id': user_id}
context = _get_context()

try:
tk.get_action(constants.PURGE_DATAREQUESTS)(context, data_dict)
except tk.ObjectNotFound as e:
log.warn(e)
return tk.abort(404, tk._('User %s not found') % user_id)
post_params = request_helpers.get_post_params()
if post_params:
if 'cancel' in post_params:
return tk.redirect_to('datarequest.index')

h.flash_notice(tk._('Deleted data request(s) for user'))
return tk.redirect_to('datarequest.index')
try:
tk.get_action(constants.PURGE_DATAREQUESTS)(context, data_dict)
h.flash_notice(tk._('Deleted data request(s) for user'))
return tk.redirect_to('datarequest.index')
except tk.ObjectNotFound as e:
log.warn(e)
return tk.abort(404, tk._('User %s not found') % user_id)
else:
return tk.render('datarequests/confirm_delete_all.html', extra_vars={'user_id': user_id})
2 changes: 1 addition & 1 deletion ckanext/datarequests/plugin_mixins/flask_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_blueprint(self):
"/{}/purge/<user_id>".format(constants.DATAREQUESTS_MAIN_PATH),
"purge",
controller_functions.purge,
('POST',),
('GET', 'POST',),
),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "page.html" %}

{% block subtitle %}{{ _("Confirm Delete") }}{% endblock %}

{% block maintag %}<div class="row" role="main">{% endblock %}

{% block main_content %}
<section class="module col-md-6 col-md-offset-3">
<div class="module-content">
{% block form %}
<p>{{ _('Are you sure you want to delete ALL data requests for user {user_id}?').format(user_id=user_id) }}</p>
<p class="form-actions">
<form id="confirm-datarequest-delete-all-form" action="{% url_for 'datarequest.purge', user_id=user_id %}" method="POST">
{% if 'csrf_input' in h %}
{{ h.csrf_input() }}
{% endif %}
<button class="btn btn-danger" type="submit" name="cancel" >{{ _('Cancel') }}</button>
<button class="btn btn-primary" type="submit" name="delete" >{{ _('Confirm Delete') }}</button>
</form>
</p>
{% endblock %}
</div>
</section>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h3 class="dataset-heading">
</h3>
{% if g.userobj.sysadmin %}
<div class="btn-group pull-right">
<a class="btn btn-danger btn-danger-serious" href="{% url_for 'datarequest.purge', user_id=datarequest.user_id %}" data-module="confirm-action" data-module-content="Are you sure you want to delete ALL data requests for this user?" title="Delete all for this user">
<a class="btn btn-danger btn-danger-serious" href="{% url_for 'datarequest.purge', user_id=datarequest.user_id %}" title="Delete all for this user">
<i class="fa fa-skull"></i>
</a>
</div>
Expand Down
2 changes: 0 additions & 2 deletions test/features/datarequest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ Feature: Datarequest
Given "TestOrgEditor" as the persona
When I log in
And I create a datarequest

Then I should see an element with xpath "//i[contains(@class, 'icon-unlock')]"
And I should see an element with xpath "//a[contains(string(), 'Close')]"

Scenario: Closing a data request will show the data request afterward
Given "DataRequestOrgAdmin" as the persona
When I log in
And I create a datarequest

And I press the element with xpath "//a[contains(string(), 'Close')]"
And I select "Requestor initiated closure" from "close_circumstance"
And I press the element with xpath "//button[contains(@class, 'btn-danger') and contains(string(), 'Close Data Request')]"
Expand Down