Skip to content

Commit

Permalink
Merge branch 'enhancement/gh-3296-add-withdraw' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
frjo committed Jul 26, 2023
2 parents c5ce2c0 + 1d7b829 commit 7ab6984
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/setup/administrators/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ The corrosponding locale dir is named: en, en_GB, en_US

FORCE_LOGIN_FOR_APPLICATION = env.bool('FORCE_LOGIN_FOR_APPLICATION', False)

### Allow Withdrawing of Submissions

ENABLE_SUBMISSION_WITHDRAWAL = env.bool('ENABLE_SUBMISSION_WITHDRAWAL', False)

### Set the allowed file extension for all uploads fields.

FILE_ALLOWED_EXTENSIONS = ['doc', 'docx', 'odp', 'ods', 'odt', 'pdf', 'ppt', 'pptx', 'rtf', 'txt', 'xls', 'xlsx']
Expand Down
3 changes: 2 additions & 1 deletion hypha/apply/funds/models/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,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 @@ -102,6 +102,11 @@ <h5>{% blocktrans with stage=object.previous.stage %}Your {{ stage }} applicatio
<svg class="icon icon--delete"><use xlink:href="#delete"></use></svg>
</a>
{% endif %}
{% if ENABLE_SUBMISSION_WITHDRAWAL and request.user.is_applicant %}
<a class="link link--withdraw-submission is-active" href="{% url 'funds:submissions:withdraw' object.id %}">
{% trans "Withdraw" %}
</a>
{% 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 @@ -27,6 +27,7 @@
SubmissionSealedView,
SubmissionStaffFlaggedView,
SubmissionUserFlaggedView,
SubmissionWithdrawView,
)
from .views_beta import (
bulk_archive_submissions,
Expand Down Expand Up @@ -101,6 +102,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
36 changes: 35 additions & 1 deletion hypha/apply/funds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 @@ -1414,6 +1418,36 @@ 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):
if not settings.ENABLE_SUBMISSION_WITHDRAWAL:
raise PermissionDenied

if not request.user.is_applicant:
raise PermissionDenied

obj = self.get_object()

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
Loading

0 comments on commit 7ab6984

Please sign in to comment.