diff --git a/hypha/apply/funds/templates/submissions/all.html b/hypha/apply/funds/templates/submissions/all.html index 5f0e5a57bc..d84de2f083 100644 --- a/hypha/apply/funds/templates/submissions/all.html +++ b/hypha/apply/funds/templates/submissions/all.html @@ -480,9 +480,10 @@ {% if can_bulk_archive %} {% if SUBMISSION_ANONYMIZATION_ENABLED %} + + + diff --git a/hypha/apply/funds/templates/submissions/bulk_delete_confirm.html b/hypha/apply/funds/templates/submissions/bulk_delete_confirm.html new file mode 100644 index 0000000000..41bf35700e --- /dev/null +++ b/hypha/apply/funds/templates/submissions/bulk_delete_confirm.html @@ -0,0 +1,16 @@ +{% load i18n %} + + +

+ {% blocktranslate trimmed with count=submission_ids|length %} + Are you sure you want to permanently delete {{ count }} submission(s)? + All data will be permanently removed. This action cannot be undone. + {% endblocktranslate %} +

+ {% for id in submission_ids %} + + {% endfor %} +
diff --git a/hypha/apply/funds/urls.py b/hypha/apply/funds/urls.py index 300cdcb87a..f9a31d4835 100644 --- a/hypha/apply/funds/urls.py +++ b/hypha/apply/funds/urls.py @@ -11,8 +11,11 @@ ) from .views.all import ( bulk_anonymize_submissions, + bulk_anonymize_submissions_confirm, bulk_archive_submissions, + bulk_archive_submissions_confirm, bulk_delete_submissions, + bulk_delete_submissions_confirm, bulk_update_submissions_status, submissions_all, ) @@ -97,8 +100,23 @@ ), path("success//", submission_success, name="success"), path("all/", submissions_all, name="list"), + path( + "all/bulk_archive_confirm/", + bulk_archive_submissions_confirm, + name="bulk-archive-confirm", + ), path("all/bulk_archive/", bulk_archive_submissions, name="bulk-archive"), + path( + "all/bulk_delete_confirm/", + bulk_delete_submissions_confirm, + name="bulk-delete-confirm", + ), path("all/bulk_delete/", bulk_delete_submissions, name="bulk-delete"), + path( + "all/bulk_anonymize_confirm/", + bulk_anonymize_submissions_confirm, + name="bulk-anonymize-confirm", + ), path("all/bulk_anonymize/", bulk_anonymize_submissions, name="bulk-anonymize"), path( "all/bulk_update_status/", diff --git a/hypha/apply/funds/views/all.py b/hypha/apply/funds/views/all.py index 90e4c37037..b899d1c036 100644 --- a/hypha/apply/funds/views/all.py +++ b/hypha/apply/funds/views/all.py @@ -9,13 +9,9 @@ from django.core.exceptions import PermissionDenied from django.core.paginator import Paginator from django.db import models -from django.http import ( - HttpRequest, - HttpResponse, - HttpResponseForbidden, -) -from django.shortcuts import render -from django.urls import reverse_lazy +from django.http import HttpRequest, HttpResponse, HttpResponseForbidden +from django.shortcuts import redirect, render +from django.urls import reverse from django.utils.translation import gettext as _ from django.views.decorators.http import require_http_methods from django_htmx.http import HttpResponseClientRedirect, HttpResponseClientRefresh @@ -348,6 +344,20 @@ def submissions_all( return render(request, template_name, ctx) +@login_required +@require_http_methods(["GET"]) +def bulk_archive_submissions_confirm(request): + if not permissions.can_bulk_archive_submissions(request.user): + return HttpResponseForbidden() + + submission_ids = request.GET.getlist("selectedSubmissionIds") + return render( + request, + "submissions/bulk_archive_confirm.html", + {"submission_ids": submission_ids}, + ) + + @login_required @require_http_methods(["POST"]) def bulk_archive_submissions(request): @@ -363,7 +373,23 @@ def bulk_archive_submissions(request): request=request, ) - return HttpResponseClientRefresh() + if request.htmx: + return HttpResponseClientRefresh() + return redirect(reverse("apply:submissions:list")) + + +@login_required +@require_http_methods(["GET"]) +def bulk_delete_submissions_confirm(request): + if not permissions.can_bulk_delete_submissions(request.user): + return HttpResponseForbidden() + + submission_ids = request.GET.getlist("selectedSubmissionIds") + return render( + request, + "submissions/bulk_delete_confirm.html", + {"submission_ids": submission_ids}, + ) @login_required @@ -381,28 +407,47 @@ def bulk_delete_submissions(request): request=request, ) - return HttpResponseClientRefresh() + if request.htmx: + return HttpResponseClientRefresh() + return redirect(reverse("apply:submissions:list")) + + +@login_required +@require_http_methods(["GET"]) +def bulk_anonymize_submissions_confirm(request): + if not settings.SUBMISSION_ANONYMIZATION_ENABLED: + return HttpResponseForbidden() + if not permissions.can_bulk_delete_submissions(request.user): + return HttpResponseForbidden() + + submission_ids = request.GET.getlist("selectedSubmissionIds") + return render( + request, + "submissions/bulk_anonymize_confirm.html", + {"submission_ids": submission_ids}, + ) @login_required @require_http_methods(["POST"]) def bulk_anonymize_submissions(request): - if settings.SUBMISSION_ANONYMIZATION_ENABLED: - if not permissions.can_bulk_delete_submissions(request.user): - return HttpResponseForbidden() + if not settings.SUBMISSION_ANONYMIZATION_ENABLED: + return HttpResponseForbidden() + if not permissions.can_bulk_delete_submissions(request.user): + return HttpResponseForbidden() - submission_ids = request.POST.getlist("selectedSubmissionIds") - submissions = ApplicationSubmission.objects.filter(id__in=submission_ids) + submission_ids = request.POST.getlist("selectedSubmissionIds") + submissions = ApplicationSubmission.objects.filter(id__in=submission_ids) - services.bulk_anonymize_submissions( - submissions=submissions, - user=request.user, - request=request, - ) + services.bulk_anonymize_submissions( + submissions=submissions, + user=request.user, + request=request, + ) + if request.htmx: return HttpResponseClientRefresh() - - return HttpResponseForbidden() + return redirect(reverse("apply:submissions:list")) @login_required @@ -446,7 +491,7 @@ def bulk_update_submissions_status(request: HttpRequest) -> HttpResponse: return HttpResponseClientRefresh() action = outcome_from_actions(transitions) return HttpResponseClientRedirect( - reverse_lazy("apply:submissions:determinations:batch") + reverse("apply:submissions:determinations:batch") + "?action=" + action + "&submissions=" diff --git a/hypha/templates/cotton/modal/confirm.html b/hypha/templates/cotton/modal/confirm.html index e7c5a3f181..d43de7ad22 100644 --- a/hypha/templates/cotton/modal/confirm.html +++ b/hypha/templates/cotton/modal/confirm.html @@ -2,7 +2,7 @@
diff --git a/hypha/templates/includes/_modal-placeholder.html b/hypha/templates/includes/_modal-placeholder.html index 6ed1ce90fd..759f8e1f65 100644 --- a/hypha/templates/includes/_modal-placeholder.html +++ b/hypha/templates/includes/_modal-placeholder.html @@ -9,6 +9,7 @@