Skip to content

Commit

Permalink
feat: add submission withdrawal
Browse files Browse the repository at this point in the history
Closes #3296
  • Loading branch information
chriszs authored and Frank Duncan committed Mar 21, 2023
1 parent 56978c8 commit 9faa366
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 4 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 @@ -834,7 +834,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 @@ -81,6 +81,13 @@ <h5>{% blocktrans with stage=object.previous.stage %}Your {{ stage }} applicatio
<svg class="icon icon--delete"><use xlink:href="#delete"></use></svg>
</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="link link--edit-submission is-active" href="{% url 'funds:submissions:edit' object.id %}">
{% trans "Edit" %}
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 @@ -13,6 +13,7 @@
RoundListView,
StaffAssignments,
SubmissionDeleteView,
SubmissionWithdrawView,
SubmissionDetailPDFView,
SubmissionDetailSimplifiedView,
SubmissionDetailView,
Expand Down Expand Up @@ -64,6 +65,7 @@
path('simplified/', SubmissionDetailSimplifiedView.as_view(), name="simplified"),
path('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(), name='serve_private_media'
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 @@ -28,7 +28,11 @@
UpdateView,
)
from django.views.generic.base import TemplateView
from django.views.generic.detail import SingleObjectMixin
from django.views.generic.detail import (
SingleObjectMixin,
BaseDetailView,
SingleObjectTemplateResponseMixin,
)
from django_file_form.models import PlaceholderUploadedFile
from django_filters.views import FilterView
from django_tables2.paginators import LazyPaginator
Expand Down Expand Up @@ -1392,6 +1396,33 @@ def delete(self, request, *args, **kwargs):
response = super().delete(request, *args, **kwargs)
return response

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
43 changes: 42 additions & 1 deletion hypha/apply/funds/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,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 @@ -356,16 +357,23 @@ def make_permissions(edit=None, review=None, view=None):
'permissions': {UserPermissions.APPLICANT, UserPermissions.STAFF, UserPermissions.LEAD, UserPermissions.ADMIN},
'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 @@ -394,6 +402,7 @@ def make_permissions(edit=None, review=None, view=None):
'permissions': {UserPermissions.APPLICANT, UserPermissions.STAFF, UserPermissions.LEAD, UserPermissions.ADMIN},
'method': 'create_revision',
},
'ext_review_withdrawn': _('Withdraw'),
},
'display': _('More information required'),
'stage': RequestExt,
Expand All @@ -410,6 +419,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 @@ -420,6 +434,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 @@ -432,11 +447,17 @@ def make_permissions(edit=None, review=None, view=None):
'permissions': {UserPermissions.APPLICANT, UserPermissions.STAFF, UserPermissions.LEAD, UserPermissions.ADMIN},
'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 @@ -445,6 +466,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 All @@ -470,7 +492,12 @@ def make_permissions(edit=None, review=None, view=None):
'ext_rejected': {
'display': _('Dismissed'),
'stage': RequestExt,
'permissions': no_permissions,
'permissions': staff_edit_permissions,
},
'ext_withdrawn': {
'display': _('Withdrawn'),
'stage': RequestExt,
'permissions': staff_edit_permissions,
},
},
]
Expand Down Expand Up @@ -1061,11 +1088,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]
DETERMINATION_RESPONSE_PHASES = [
Expand Down Expand Up @@ -1159,6 +1196,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/src/sass/apply/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 9faa366

Please sign in to comment.