Skip to content

Commit 5b656bb

Browse files
committed
Improve withdrawal permissions and error handling
The permissions on the `*withdraw` items should be `no_permissions`. After a submission is withdrawn, nothing further should happen to it. When `perform_transition` is called in the View, that function will already check for valid transitions and raise an exception if needed. So do not bother looking into the transitions, instead look directly for the withdraw action. And expect exactly one of those, otherwise raise an exception with details of expectations. Issue #3296
1 parent f63f0b2 commit 5b656bb

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

hypha/apply/funds/views.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.contrib.auth.mixins import UserPassesTestMixin
1111
from django.contrib.auth.models import Group
1212
from django.contrib.humanize.templatetags.humanize import intcomma
13-
from django.core.exceptions import PermissionDenied
13+
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
1414
from django.db.models import Count, Q
1515
from django.forms import BaseModelForm
1616
from django.http import (
@@ -1601,16 +1601,22 @@ def withdraw(self, request, *args, **kwargs):
16011601
obj = self.get_object()
16021602

16031603
withdraw_actions = [
1604-
action
1605-
for action in obj.workflow[obj.status].transitions.keys()
1606-
if "withdraw" in action
1604+
action for action in obj.workflow.keys() if "withdraw" in action
16071605
]
16081606

1609-
if len(withdraw_actions) > 0:
1607+
if len(withdraw_actions) == 1:
16101608
action = withdraw_actions[0]
16111609
obj.perform_transition(
16121610
action, self.request.user, request=self.request, notify=False
16131611
)
1612+
elif len(withdraw_actions) > 1:
1613+
raise ImproperlyConfigured(
1614+
f'In workflow "{obj.workflow}" too many withdraw actions: "{withdraw_actions}"'
1615+
)
1616+
elif len(withdraw_actions) < 1:
1617+
raise ImproperlyConfigured(
1618+
f'No withdraw actions found in workflow "{obj.workflow}"'
1619+
)
16141620

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

hypha/apply/funds/workflow.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None):
391391
"withdrawn": {
392392
"display": _("Withdrawn"),
393393
"stage": Request,
394-
"permissions": staff_edit_permissions,
394+
"permissions": no_permissions,
395395
},
396396
},
397397
]
@@ -443,11 +443,6 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None):
443443
"stage": RequestExt,
444444
"permissions": applicant_edit_permissions,
445445
},
446-
"ext_withdrawn": {
447-
"display": _("Withdrawn"),
448-
"stage": RequestExt,
449-
"permissions": staff_edit_permissions,
450-
},
451446
},
452447
{
453448
"ext_internal_review": {
@@ -585,7 +580,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None):
585580
"ext_withdrawn": {
586581
"display": _("Withdrawn"),
587582
"stage": RequestExt,
588-
"permissions": staff_edit_permissions,
583+
"permissions": no_permissions,
589584
},
590585
},
591586
]
@@ -803,7 +798,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None):
803798
"com_withdrawn": {
804799
"display": _("Withdrawn"),
805800
"stage": RequestCom,
806-
"permissions": staff_edit_permissions,
801+
"permissions": no_permissions,
807802
},
808803
},
809804
]
@@ -1140,7 +1135,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None):
11401135
"proposal_withdrawn": {
11411136
"display": _("Withdrawn"),
11421137
"stage": Proposal,
1143-
"permissions": staff_edit_permissions,
1138+
"permissions": no_permissions,
11441139
},
11451140
},
11461141
]

0 commit comments

Comments
 (0)