Skip to content

Commit

Permalink
feat: add submission withdrawal
Browse files Browse the repository at this point in the history
Issue #3296
  • Loading branch information
chriszs authored and bickelj committed Jul 24, 2024
1 parent 1518221 commit e278571
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hypha/apply/funds/models/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ def in_external_review_phase(self):
def is_finished(self):
accepted = self.status in PHASES_MAPPING["accepted"]["statuses"]
dismissed = self.status in PHASES_MAPPING["dismissed"]["statuses"]
return accepted or dismissed
withdrawn = self.status in PHASES_MAPPING["withdrawn"]["statuses"]
return accepted or dismissed or withdrawn

# Methods for accessing data on the submission

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base-apply.html" %}
{% load i18n static %}

{% block title %}{% trans "Withdrawing" %}: {{object.title }}{% endblock %}

{% block content %}
<div class="admin-bar">
<div class="admin-bar__inner">
<h2 class="heading heading--no-margin">{% trans "Withdrawing" %}: {{ object.title }}</h2>
</div>
</div>

<div class="wrapper wrapper--light-grey-bg wrapper--form wrapper--sidebar">
<div class="wrapper--sidebar--inner">
<form class="form" action="" method="post">
{% csrf_token %}
<p><strong>{% blocktrans %}Are you sure you want to withdraw "{{ object }}" from consideration?{% endblocktrans %}</strong></p>
<button class="button button--warning button--submit button--top-space" type="submit">{% trans "Confirm" %}</button>
</form>
</div>
</div>

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ <h5>{% blocktrans with stage=object.previous.stage %}Your {{ stage }} applicatio
{% trans "Delete" %}
</a>
{% endif %}
{% if request.user|has_edit_perm:object %}
{% if request.user.is_applicant %}
<a
class="link link--withdraw-submission is-active"
href="{% url 'funds:submissions:withdraw' object.id %}">
{% trans "Withdraw" %}
</a>
{% endif %}
{% endif %}
{% if request.user|has_edit_perm:object %}
<a
class="font-bold flex items-center hover:opacity-70 transition-opacity"
Expand Down
2 changes: 2 additions & 0 deletions hypha/apply/funds/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SubmissionsByRound,
SubmissionsByStatus,
SubmissionSealedView,
SubmissionWithdrawView,
partial_screening_card,
submission_success,
)
Expand Down Expand Up @@ -194,6 +195,7 @@
"download/", SubmissionDetailPDFView.as_view(), name="download"
),
path("delete/", SubmissionDeleteView.as_view(), name="delete"),
path('withdraw/', SubmissionWithdrawView.as_view(), name="withdraw"),
path(
"documents/<uuid:field_id>/<str:file_name>",
SubmissionPrivateMediaView.as_view(),
Expand Down
33 changes: 32 additions & 1 deletion hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
UpdateView,
)
from django.views.generic.base import TemplateView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.detail import (
BaseDetailView,
SingleObjectMixin,
SingleObjectTemplateResponseMixin,
)
from django_file_form.models import PlaceholderUploadedFile
from django_filters.views import FilterView
from django_tables2.paginators import LazyPaginator
Expand Down Expand Up @@ -1578,6 +1582,33 @@ def form_valid(self, form):
# delete submission and redirect to success url
return super().form_valid(form)

class SubmissionWithdrawView(SingleObjectTemplateResponseMixin, BaseDetailView):
model = ApplicationSubmission
success_url = reverse_lazy('funds:submissions:list')
template_name_suffix = '_confirm_withdraw'

def post(self, request, *args, **kwargs):
return self.withdraw(request, *args, **kwargs)

def withdraw(self, request, *args, **kwargs):
obj = self.get_object()

if not obj.phase.permissions.can_edit(request.user):
raise PermissionDenied

withdraw_actions = [action for action in obj.workflow[obj.status].transitions.keys() if 'withdraw' in action]

if len(withdraw_actions) > 0:
action = withdraw_actions[0]
obj.perform_transition(
action,
self.request.user,
request=self.request,
notify=False
)

success_url = obj.get_absolute_url()
return HttpResponseRedirect(success_url)

@method_decorator(login_required, name="dispatch")
class SubmissionPrivateMediaView(UserPassesTestMixin, PrivateMediaView):
Expand Down
41 changes: 41 additions & 0 deletions hypha/apply/funds/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def make_permissions(edit=None, review=None, view=None):
"ext_internal_review": _("Open Review"),
"ext_determination": _("Ready For Determination"),
"ext_rejected": _("Dismiss"),
"ext_screening_withdrawn": _("Withdraw"),
},
"display": _("Need screening"),
"public": _("Application Received"),
Expand All @@ -420,16 +421,23 @@ def make_permissions(edit=None, review=None, view=None):
},
"method": "create_revision",
},
"ext_screening_withdrawn": _("Withdraw"),
},
"display": _("More information required"),
"stage": RequestExt,
"permissions": applicant_edit_permissions,
},
"ext_screening_withdrawn": {
"display": _("Withdrawn"),
"stage": RequestExt,
"permissions": staff_edit_permissions,
},
},
{
"ext_internal_review": {
"transitions": {
"ext_post_review_discussion": _("Close Review"),
"ext_review_withdrawn": _("Withdraw"),
INITIAL_STATE: _("Need screening (revert)"),
},
"display": _("Internal Review"),
Expand Down Expand Up @@ -465,6 +473,7 @@ def make_permissions(edit=None, review=None, view=None):
},
"method": "create_revision",
},
"ext_review_withdrawn": _("Withdraw"),
},
"display": _("More information required"),
"stage": RequestExt,
Expand All @@ -481,6 +490,11 @@ def make_permissions(edit=None, review=None, view=None):
"stage": RequestExt,
"permissions": reviewer_review_permissions,
},
"ext_review_withdrawn": {
"display": _("Withdrawn"),
"stage": RequestExt,
"permissions": staff_edit_permissions,
},
},
{
"ext_post_external_review_discussion": {
Expand All @@ -491,6 +505,7 @@ def make_permissions(edit=None, review=None, view=None):
"ext_almost": _("Accept but additional info required"),
"ext_accepted": _("Accept"),
"ext_rejected": _("Dismiss"),
"ext_external_review_withdrawn": _("Withdraw"),
},
"display": _("Ready For Discussion"),
"stage": RequestExt,
Expand All @@ -508,11 +523,17 @@ def make_permissions(edit=None, review=None, view=None):
},
"method": "create_revision",
},
"ext_external_review_withdrawn": _("Withdraw"),
},
"display": _("More information required"),
"stage": RequestExt,
"permissions": applicant_edit_permissions,
},
"ext_external_review_withdrawn": {
"display": _("Withdrawn"),
"stage": RequestExt,
"permissions": staff_edit_permissions,
},
},
{
"ext_determination": {
Expand All @@ -523,6 +544,7 @@ def make_permissions(edit=None, review=None, view=None):
"ext_almost": _("Accept but additional info required"),
"ext_accepted": _("Accept"),
"ext_rejected": _("Dismiss"),
"ext_withdrawn": _("Withdraw"),
},
"display": _("Ready for Determination"),
"permissions": hidden_from_applicant_permissions,
Expand Down Expand Up @@ -552,6 +574,11 @@ def make_permissions(edit=None, review=None, view=None):
"stage": RequestExt,
"permissions": no_permissions,
},
"ext_withdrawn": {
"display": _("Withdrawn"),
"stage": RequestExt,
"permissions": staff_edit_permissions,
},
},
]

Expand Down Expand Up @@ -1214,11 +1241,21 @@ def get_dismissed_statuses():
return dismissed_statuses


def get_withdrawn_statuses():
withdrawn_statuses = set()
for phase_name, phase in PHASES:
if phase.display_name == "Dismissed":
withdrawn_statuses.add(phase_name)
return withdrawn_statuses


ext_or_higher_statuses = get_ext_or_higher_statuses()
review_statuses = get_review_statuses()
ext_review_statuses = get_ext_review_statuses()
ext_or_higher_statuses = get_ext_or_higher_statuses()
accepted_statuses = get_accepted_statuses()
dismissed_statuses = get_dismissed_statuses()
withdrawn_statuses = get_withdrawn_statuses()

DETERMINATION_PHASES = [
phase_name for phase_name, _ in PHASES if "_discussion" in phase_name
Expand Down Expand Up @@ -1317,6 +1354,10 @@ def phases_matching(phrase, exclude=None):
"name": _("Dismissed"),
"statuses": phases_matching("rejected"),
},
"withdrawn": {
"name": _("Withdrawn"),
"statuses": phases_matching("withdrawn"),
},
}

OPEN_CALL_PHASES = [
Expand Down
7 changes: 6 additions & 1 deletion hypha/static_src/sass/custom/_custom.scss
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
// stylelint-disable no-empty-source
.link--withdraw-submission {
margin-right: 1rem;
padding-right: 1rem;
border-right: 2px solid #cfcfcf;
font-weight: 700;
}

0 comments on commit e278571

Please sign in to comment.