From b360613f7109dee06a75ced68ba70ed0dd5cf83c Mon Sep 17 00:00:00 2001 From: Peyman Karimi Date: Tue, 12 Apr 2022 11:09:54 +0200 Subject: [PATCH] NEW: Excluded transitions added. --- djangorestframework_fsm/viewset_mixins.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/djangorestframework_fsm/viewset_mixins.py b/djangorestframework_fsm/viewset_mixins.py index 380de46..5886b0c 100644 --- a/djangorestframework_fsm/viewset_mixins.py +++ b/djangorestframework_fsm/viewset_mixins.py @@ -21,6 +21,9 @@ def transition_action(self, request, *args, **kwargs): if not has_transition_perm(transition_method, self.request.user): raise exceptions.PermissionDenied + if transition_name in self.excluded_transitions: + raise exceptions.PermissionDenied + if hasattr(self, 'get_{0}_kwargs'.format(transition_name)): transition_kwargs = getattr(self, 'get_{0}_kwargs'.format(transition_name))() else: @@ -68,6 +71,7 @@ def get_drf_fsm_mixin(Model, fieldname='state'): class Mixin(object): save_after_transition = True return_result_of = [] + excluded_transitions = [] @action(methods=['GET'], detail=True, url_name='possible-transitions', url_path='possible-transitions') def possible_transitions(self, request, *args, **kwargs): @@ -77,7 +81,7 @@ def possible_transitions(self, request, *args, **kwargs): 'transitions': [ trans.name.replace('_', '-') for trans in getattr(instance, 'get_available_{}_transitions'.format(fieldname))() - if trans.has_perm(instance, request.user) + if trans.has_perm(instance, request.user) and (trans.name not in self.excluded_transitions) ] }, )