Make workflow states cancel their active task states on cancel()

pull/6257/head
jacobtoppm 2020-04-09 15:45:44 +01:00 zatwierdzone przez Matt Westcott
rodzic e0699e0a67
commit dec7f8ed46
2 zmienionych plików z 8 dodań i 0 usunięć

Wyświetl plik

@ -923,6 +923,8 @@ class TestDisableViews(TestCase, WagtailTestUtils):
self.assertEqual(states.filter(status=WorkflowState.STATUS_IN_PROGRESS).count(), 0) self.assertEqual(states.filter(status=WorkflowState.STATUS_IN_PROGRESS).count(), 0)
self.assertEqual(states.filter(status=WorkflowState.STATUS_CANCELLED).count(), 1) self.assertEqual(states.filter(status=WorkflowState.STATUS_CANCELLED).count(), 1)
self.assertEqual(TaskState.objects.filter(workflow_state__workflow=self.workflow, status=TaskState.STATUS_IN_PROGRESS).count(), 0)
def test_disable_task(self): def test_disable_task(self):
"""Test that deactivating a task sets it to inactive and cancels in progress states""" """Test that deactivating a task sets it to inactive and cancels in progress states"""
self.login(self.submitter) self.login(self.submitter)

Wyświetl plik

@ -2837,6 +2837,9 @@ class WorkflowState(models.Model):
def update(self, user=None, next_task=None): def update(self, user=None, next_task=None):
"""Checks the status of the current task, and progresses (or ends) the workflow if appropriate. If the workflow progresses, """Checks the status of the current task, and progresses (or ends) the workflow if appropriate. If the workflow progresses,
next_task will be used to start a specific task next if provided.""" next_task will be used to start a specific task next if provided."""
if self.status != self.STATUS_IN_PROGRESS:
# Updating a completed or cancelled workflow should have no effect
return
try: try:
current_status = self.current_task_state.status current_status = self.current_task_state.status
except AttributeError: except AttributeError:
@ -2880,6 +2883,9 @@ class WorkflowState(models.Model):
raise PermissionDenied raise PermissionDenied
self.status = self.STATUS_CANCELLED self.status = self.STATUS_CANCELLED
self.save() self.save()
for state in self.task_states.filter(status=TaskState.STATUS_IN_PROGRESS):
# Cancel all in progress task states
state.specific.cancel(user=user)
workflow_cancelled.send(sender=self.__class__, instance=self, user=user) workflow_cancelled.send(sender=self.__class__, instance=self, user=user)
@transaction.atomic @transaction.atomic