Skip to content

Commit 2b72a80

Browse files
committed
Permission fixes.
1 parent 13fc0ae commit 2b72a80

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
@@ -147,6 +147,7 @@
147147
PHASES_MAPPING,
148148
STAGE_CHANGE_ACTIONS,
149149
active_statuses,
150+
get_withdraw_action_for_stage,
150151
review_statuses,
151152
)
152153

@@ -1796,43 +1797,39 @@ def form_valid(self, form):
17961797
return super().form_valid(form)
17971798

17981799

1799-
class SubmissionWithdrawView(SingleObjectTemplateResponseMixin, BaseDetailView):
1800+
@method_decorator(login_required, name="dispatch")
1801+
class SubmissionWithdrawView(
1802+
SingleObjectTemplateResponseMixin, UserPassesTestMixin, BaseDetailView
1803+
):
18001804
model = ApplicationSubmission
18011805
success_url = reverse_lazy("funds:submissions:list")
18021806
template_name_suffix = "_confirm_withdraw"
18031807

1808+
def dispatch(self, *args, **kwargs):
1809+
self.submission = self.get_object()
1810+
return super().dispatch(*args, **kwargs)
1811+
18041812
def post(self, request, *args, **kwargs):
18051813
return self.withdraw(request, *args, **kwargs)
18061814

18071815
def withdraw(self, request, *args, **kwargs):
1808-
if not settings.ENABLE_SUBMISSION_WITHDRAWAL:
1809-
raise PermissionDenied
1816+
withdraw_action = get_withdraw_action_for_stage(self.submission.stage)
18101817

1811-
if not request.user.is_applicant:
1812-
raise PermissionDenied
1813-
1814-
obj = self.get_object()
1815-
1816-
withdraw_actions = [
1817-
action for action in obj.workflow.keys() if "withdraw" in action
1818-
]
1819-
1820-
if len(withdraw_actions) == 1:
1821-
action = withdraw_actions[0]
1822-
obj.perform_transition(
1823-
action, self.request.user, request=self.request, notify=False
1824-
)
1825-
elif len(withdraw_actions) > 1:
1826-
raise ImproperlyConfigured(
1827-
f'In workflow "{obj.workflow}" too many withdraw actions: "{withdraw_actions}"'
1818+
if withdraw_action:
1819+
self.submission.perform_transition(
1820+
withdraw_action, self.request.user, request=self.request, notify=False
18281821
)
1829-
elif len(withdraw_actions) < 1:
1822+
else:
18301823
raise ImproperlyConfigured(
1831-
f'No withdraw actions found in workflow "{obj.workflow}"'
1824+
f'No withdraw actions found in workflow "{self.submission.workflow}"'
18321825
)
18331826

1834-
success_url = obj.get_absolute_url()
1835-
return HttpResponseRedirect(success_url)
1827+
return HttpResponseRedirect(self.submission.get_absolute_url())
1828+
1829+
def test_func(self):
1830+
can_withdraw = self.submission.phase.permissions.can_withdraw(self.request.user)
1831+
1832+
return settings.ENABLE_SUBMISSION_WITHDRAWAL and can_withdraw
18361833

18371834

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

0 commit comments

Comments
 (0)