Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions hypha/apply/funds/templates/submissions/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,10 @@

{% if can_bulk_archive %}
<button
hx-post="{% url 'apply:submissions:bulk-archive' %}"
hx-get="{% url 'apply:submissions:bulk-archive-confirm' %}"
hx-include="[name='selectedSubmissionIds']"
hx-confirm="{% trans 'Are you sure you want to archive the selected submissions?' %}"
hx-target="#htmx-modal"
hx-swap="innerHTML"
class="btn btn-sm"
>
{% heroicon_outline "lock-closed" aria_hidden="true" size=14 class="stroke-base-content/80" %}
Expand All @@ -492,19 +493,21 @@

{% if can_bulk_delete %}
<button
hx-post="{% url 'apply:submissions:bulk-delete' %}"
hx-get="{% url 'apply:submissions:bulk-delete-confirm' %}"
hx-include="[name='selectedSubmissionIds']"
hx-confirm="{% trans 'Are you sure you want to delete the selected submissions? This action cannot be undone.' %}"
hx-target="#htmx-modal"
hx-swap="innerHTML"
class="btn btn-sm"
>
{% heroicon_outline "trash" aria_hidden="true" size=14 class="stroke-base-content/80" %}
{% trans "Delete" %}
</button>
{% if SUBMISSION_ANONYMIZATION_ENABLED %}
<button
hx-post="{% url 'apply:submissions:bulk-anonymize' %}"
hx-get="{% url 'apply:submissions:bulk-anonymize-confirm' %}"
hx-include="[name='selectedSubmissionIds']"
hx-confirm="{% trans 'Are you sure you want to anonymize the selected submissions? All draft submission will be deleted. This action cannot be undone.' %}"
hx-target="#htmx-modal"
hx-swap="innerHTML"
class="btn btn-sm"
>
{% heroicon_outline "user-minus" aria_hidden="true" size=14 class="stroke-base-content/80" %}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% load i18n %}

<c-modal.confirm
title="{% trans 'Anonymize applications' %}"
action="{% url 'apply:submissions:bulk-anonymize' %}"
initial_mode="anonymize"
>
<p class="text-sm text-fg-muted">
{% blocktranslate trimmed with count=submission_ids|length %}
Are you sure you want to anonymize {{ count }} submission(s)?
Personal data will be removed and applications will only be accessible
via statistics in the Results view. All draft submissions will be deleted.
This action cannot be undone.
{% endblocktranslate %}
</p>
{% for id in submission_ids %}
<input type="hidden" name="selectedSubmissionIds" value="{{ id }}">
{% endfor %}
</c-modal.confirm>
39 changes: 39 additions & 0 deletions hypha/apply/funds/templates/submissions/bulk_archive_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% load i18n heroicons %}

<form class="px-4 pt-5 pb-4 sm:p-6 form" action="{% url 'apply:submissions:bulk-archive' %}" method="post">
{% csrf_token %}

<div class="sm:flex sm:items-start">
<div class="flex justify-center items-center mx-auto w-12 h-12 rounded-full sm:mx-0 sm:w-10 sm:h-10 bg-warning/10 shrink-0">
{% heroicon_outline "exclamation-triangle" class="w-6 h-6 text-warning" stroke_width="1.5" aria_hidden="true" %}
</div>
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3 class="text-base font-semibold leading-6 text-base-content" id="modal-title">{% trans "Archive submissions" %}</h3>
<div class="mt-2">
<p class="text-sm text-fg-muted">
{% blocktranslate trimmed with count=submission_ids|length %}
Are you sure you want to archive {{ count }} submission(s)?
Archived submissions will be hidden from the main list and cannot be edited.
Submissions can be unarchived at any time.
{% endblocktranslate %}
</p>
</div>
</div>
</div>

{% for id in submission_ids %}
<input type="hidden" name="selectedSubmissionIds" value="{{ id }}">
{% endfor %}

<div class="mt-5 sm:flex-row-reverse sm:mt-4 card-actions">
<button
type="submit"
class="w-full sm:w-auto btn btn-warning"
>{% trans "Archive" %}</button>
<button
type="button"
class="w-full sm:w-auto btn btn-secondary btn-outline btn-soft"
@click="show = false"
>{% trans "Cancel" %}</button>
</div>
</form>
16 changes: 16 additions & 0 deletions hypha/apply/funds/templates/submissions/bulk_delete_confirm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% load i18n %}

<c-modal.confirm
title="{% trans 'Delete applications' %}"
action="{% url 'apply:submissions:bulk-delete' %}"
>
<p class="text-sm text-fg-muted">
{% 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 %}
</p>
{% for id in submission_ids %}
<input type="hidden" name="selectedSubmissionIds" value="{{ id }}">
{% endfor %}
</c-modal.confirm>
18 changes: 18 additions & 0 deletions hypha/apply/funds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -97,8 +100,23 @@
),
path("success/<int:pk>/", 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/",
Expand Down
89 changes: 67 additions & 22 deletions hypha/apply/funds/views/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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="
Expand Down
2 changes: 1 addition & 1 deletion hypha/templates/cotton/modal/confirm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<form
class="px-4 pt-5 pb-4 sm:p-6"
action="{{ request.path }}"
action="{% if action %}{{ action }}{% else %}{{ request.path }}{% endif %}"
method="post"
x-data="{userConfirmationInput: '', delConfirmText: `{% trans 'delete' %}`, anonConfirmText: `{% trans 'anonymize' %}`, mode: '{{ initial_mode|default:'delete' }}'}"
>
Expand Down
2 changes: 2 additions & 0 deletions hypha/templates/includes/_modal-placeholder.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div
x-cloak
x-data="{ show: false }"
x-init="$watch('show', v => { if (!v) $nextTick(() => { $refs.modalContent.innerHTML = '' }) })"
@keydown.window.escape="show = false"
x-show="show"
class="relative z-10"
Expand Down Expand Up @@ -45,6 +46,7 @@
x-description="Modal panel, show/hide based on modal state."
class="relative w-full text-left rounded-lg border shadow-xl transition-all transform sm:my-8 sm:max-w-lg bg-base-100"
id="htmx-modal"
x-ref="modalContent"
hx-target="this"
@htmx:after-swap="show = true"
@htmx:before-swap="if(!$event.detail.xhr.response) { show = false; $event.detail.shouldSwap = false;}"
Expand Down
Loading