Skip to content

Commit a41caec

Browse files
committed
Permission fixes.
1 parent 1ba9685 commit a41caec

File tree

2 files changed

+245
-68
lines changed

2 files changed

+245
-68
lines changed

hypha/apply/funds/views.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
PHASES_MAPPING,
137137
STAGE_CHANGE_ACTIONS,
138138
active_statuses,
139+
get_withdraw_action_for_stage,
139140
review_statuses,
140141
)
141142

@@ -1583,43 +1584,39 @@ def form_valid(self, form):
15831584
return super().form_valid(form)
15841585

15851586

1586-
class SubmissionWithdrawView(SingleObjectTemplateResponseMixin, BaseDetailView):
1587+
@method_decorator(login_required, name="dispatch")
1588+
class SubmissionWithdrawView(
1589+
SingleObjectTemplateResponseMixin, UserPassesTestMixin, BaseDetailView
1590+
):
15871591
model = ApplicationSubmission
15881592
success_url = reverse_lazy("funds:submissions:list")
15891593
template_name_suffix = "_confirm_withdraw"
15901594

1595+
def dispatch(self, *args, **kwargs):
1596+
self.submission = self.get_object()
1597+
return super().dispatch(*args, **kwargs)
1598+
15911599
def post(self, request, *args, **kwargs):
15921600
return self.withdraw(request, *args, **kwargs)
15931601

15941602
def withdraw(self, request, *args, **kwargs):
1595-
if not settings.ENABLE_SUBMISSION_WITHDRAWAL:
1596-
raise PermissionDenied
1597-
1598-
if not request.user.is_applicant:
1599-
raise PermissionDenied
1600-
1601-
obj = self.get_object()
1603+
withdraw_action = get_withdraw_action_for_stage(self.submission.stage)
16021604

1603-
withdraw_actions = [
1604-
action for action in obj.workflow.keys() if "withdraw" in action
1605-
]
1606-
1607-
if len(withdraw_actions) == 1:
1608-
action = withdraw_actions[0]
1609-
obj.perform_transition(
1610-
action, self.request.user, request=self.request, notify=False
1611-
)
1612-
elif len(withdraw_actions) > 1:
1613-
raise ImproperlyConfigured(
1614-
f'In workflow "{obj.workflow}" too many withdraw actions: "{withdraw_actions}"'
1605+
if withdraw_action:
1606+
self.submission.perform_transition(
1607+
withdraw_action, self.request.user, request=self.request, notify=False
16151608
)
1616-
elif len(withdraw_actions) < 1:
1609+
else:
16171610
raise ImproperlyConfigured(
1618-
f'No withdraw actions found in workflow "{obj.workflow}"'
1611+
f'No withdraw actions found in workflow "{self.submission.workflow}"'
16191612
)
16201613

1621-
success_url = obj.get_absolute_url()
1622-
return HttpResponseRedirect(success_url)
1614+
return HttpResponseRedirect(self.submission.get_absolute_url())
1615+
1616+
def test_func(self):
1617+
can_withdraw = self.submission.phase.permissions.can_withdraw(self.request.user)
1618+
1619+
return settings.ENABLE_SUBMISSION_WITHDRAWAL and can_withdraw
16231620

16241621

16251622
@method_decorator(login_required, name="dispatch")

0 commit comments

Comments
 (0)