workflow - do not show disabled (not active) tasks in the task chooser modal

- fixes #7401
pull/7544/head
LB Johnston 2021-08-31 22:03:29 +10:00 zatwierdzone przez nmorduch
rodzic 607d356076
commit d6bb9bb5c0
3 zmienionych plików z 13 dodań i 4 usunięć

Wyświetl plik

@ -48,6 +48,7 @@ Changelog
* Fix: Add `gettext_lazy` to `ModelAdmin` built in view titles so that language settings are correctly used (Matt Westcott)
* Fix: Tabbing and keyboard interaction on the Wagtail userbar now aligns with ARIA best practices (Storm Heg)
* Fix: Add full support for custom `edit_handler` usage by adding missing `bind_to` call to `PreviewOnEdit` view (Stefan Hammer)
* Fix: Only show active (not disabled) tasks in the workflow task chooser (LB Johnston)
2.14.1 (12.08.2021)

Wyświetl plik

@ -1586,6 +1586,9 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
self.task_enabled = GroupApprovalTask.objects.create(name='Enabled foo')
self.task_disabled = GroupApprovalTask.objects.create(name='Disabled foo', active=False)
def test_get(self):
response = self.client.get(reverse('wagtailadmin_workflows:task_chooser'))
@ -1598,6 +1601,8 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/results.html")
self.assertTemplateNotUsed(response, "wagtailadmin/workflows/task_chooser/includes/create_form.html")
self.assertFalse(response.context['searchform'].is_searching())
# check that only active (non-disabled) tasks are listed
self.assertEqual([_.name for _ in response.context['tasks'].object_list], ['Enabled foo', 'Moderators approval'])
def test_search(self):
response = self.client.get(reverse('wagtailadmin_workflows:task_chooser') + '?q=foo')
@ -1607,6 +1612,9 @@ class TestTaskChooserView(TestCase, WagtailTestUtils):
self.assertTemplateUsed(response, "wagtailadmin/workflows/task_chooser/includes/results.html")
self.assertTemplateNotUsed(response, "wagtailadmin/workflows/task_chooser/chooser.html")
self.assertTrue(response.context['searchform'].is_searching())
self.assertEqual(response.context['query_string'], 'foo')
# check that only active (non-disabled) tasks are listed
self.assertEqual([_.name for _ in response.context['tasks'].object_list], ['Enabled foo'])
def test_pagination(self):
response = self.client.get(reverse('wagtailadmin_workflows:task_chooser') + '?p=2')

Wyświetl plik

@ -446,8 +446,8 @@ class DisableTask(DeleteView):
context = super().get_context_data(**kwargs)
states_in_progress = TaskState.objects.filter(status=TaskState.STATUS_IN_PROGRESS, task=self.get_object().pk).count()
context['warning_message'] = ngettext(
'This task is in progress on %(states_in_progress)d page. Disabling this task will cause it to be skipped in the moderation workflow.',
'This task is in progress on %(states_in_progress)d pages. Disabling this task will cause it to be skipped in the moderation workflow.',
'This task is in progress on %(states_in_progress)d page. Disabling this task will cause it to be skipped in the moderation workflow and not be listed for selection when editing a workflow.',
'This task is in progress on %(states_in_progress)d pages. Disabling this task will cause it to be skipped in the moderation workflow and not be listed for selection when editing a workflow.',
states_in_progress,
) % {
'states_in_progress': states_in_progress,
@ -550,7 +550,7 @@ def task_chooser(request):
q = None
if 'q' in request.GET or 'p' in request.GET or 'task_type' in request.GET:
searchform = TaskChooserSearchForm(request.GET, task_type_choices=task_type_choices)
tasks = all_tasks = searchform.task_model.objects.order_by(Lower('name'))
tasks = all_tasks = searchform.task_model.objects.filter(active=True).order_by(Lower('name'))
q = ''
if searchform.is_searching():
@ -599,7 +599,7 @@ def task_chooser(request):
createform = None
searchform = TaskChooserSearchForm(task_type_choices=task_type_choices)
tasks = searchform.task_model.objects.order_by(Lower('name'))
tasks = searchform.task_model.objects.filter(active=True).order_by(Lower('name'))
paginator = Paginator(tasks, per_page=10)
tasks = paginator.get_page(request.GET.get('p'))