diff --git a/hypha/apply/funds/views.py b/hypha/apply/funds/views.py index f7ad374224..74fa8f72a9 100644 --- a/hypha/apply/funds/views.py +++ b/hypha/apply/funds/views.py @@ -14,7 +14,7 @@ ) from django.contrib.auth.mixins import UserPassesTestMixin from django.contrib.auth.models import Group -from django.core.exceptions import PermissionDenied +from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.db.models import Count, Q from django.forms import BaseModelForm from django.http import ( @@ -1814,16 +1814,22 @@ def withdraw(self, request, *args, **kwargs): obj = self.get_object() withdraw_actions = [ - action - for action in obj.workflow[obj.status].transitions.keys() - if "withdraw" in action + action for action in obj.workflow.keys() if "withdraw" in action ] - if len(withdraw_actions) > 0: + if len(withdraw_actions) == 1: action = withdraw_actions[0] obj.perform_transition( action, self.request.user, request=self.request, notify=False ) + elif len(withdraw_actions) > 1: + raise ImproperlyConfigured( + f'In workflow "{obj.workflow}" too many withdraw actions: "{withdraw_actions}"' + ) + elif len(withdraw_actions) < 1: + raise ImproperlyConfigured( + f'No withdraw actions found in workflow "{obj.workflow}"' + ) success_url = obj.get_absolute_url() return HttpResponseRedirect(success_url) diff --git a/hypha/apply/funds/workflow.py b/hypha/apply/funds/workflow.py index 79ce0f0254..90c606fb0e 100644 --- a/hypha/apply/funds/workflow.py +++ b/hypha/apply/funds/workflow.py @@ -391,7 +391,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None): "withdrawn": { "display": _("Withdrawn"), "stage": Request, - "permissions": staff_edit_permissions, + "permissions": no_permissions, }, }, ] @@ -443,11 +443,6 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None): "stage": RequestExt, "permissions": applicant_edit_permissions, }, - "ext_withdrawn": { - "display": _("Withdrawn"), - "stage": RequestExt, - "permissions": staff_edit_permissions, - }, }, { "ext_internal_review": { @@ -585,7 +580,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None): "ext_withdrawn": { "display": _("Withdrawn"), "stage": RequestExt, - "permissions": staff_edit_permissions, + "permissions": no_permissions, }, }, ] @@ -803,7 +798,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None): "com_withdrawn": { "display": _("Withdrawn"), "stage": RequestCom, - "permissions": staff_edit_permissions, + "permissions": no_permissions, }, }, ] @@ -1140,7 +1135,7 @@ def make_permissions(edit=None, review=None, view=None, withdraw=None): "proposal_withdrawn": { "display": _("Withdrawn"), "stage": Proposal, - "permissions": staff_edit_permissions, + "permissions": no_permissions, }, }, ]