From 068c3f296470cfa73ef093743d6205697990bc5e Mon Sep 17 00:00:00 2001 From: John-Scott Atlakson <24574+jsma@users.noreply.github.com> Date: Wed, 14 Feb 2024 12:02:15 -0800 Subject: [PATCH] Added `AbstractGroupApprovalTask` to simplify customizing behavior --- CHANGELOG.txt | 1 + docs/extending/custom_tasks.md | 9 +++++++-- docs/releases/6.1.md | 1 + wagtail/models/__init__.py | 7 ++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 05084db92823..b6c737d47da3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -124,6 +124,7 @@ Changelog * Add API support for a redirects (contrib) endpoint (Rohit Sharma, Jaap Roes, Andreas Donig) * Add the default ability for all `SnippetViewSet` & `ModelViewSet` to support being copied (Shlomo Markowitz) * Support dynamic Wagtail guide links in the admin that are based on the running version of Wagtail (Tidiane Dia) + * Added `AbstractGroupApprovalTask` to simplify customizing behavior of custom `Task` models (John-Scott Atlakson) * Fix: Update system check for overwriting storage backends to recognize the `STORAGES` setting introduced in Django 4.2 (phijma-leukeleu) * Fix: Prevent password change form from raising a validation error when browser autocomplete fills in the "Old password" field (Chiemezuo Akujobi) * Fix: Ensure that the legacy dropdown options, when closed, do not get accidentally clicked by other interactions on wide viewports (CheesyPhoenix, Christer Jensen) diff --git a/docs/extending/custom_tasks.md b/docs/extending/custom_tasks.md index 48b7f7664563..f4562f448bf8 100644 --- a/docs/extending/custom_tasks.md +++ b/docs/extending/custom_tasks.md @@ -4,11 +4,16 @@ The Workflow system allows users to create tasks, which represent stages of mode Wagtail provides one built-in task type: `GroupApprovalTask`, which allows any user in specific groups to approve or reject moderation. -However, it is possible to implement your own task types. Instances of your custom task can then be created in the `Tasks` section of the Wagtail Admin. +However, it is possible to implement your own task types. Instances of your custom task can then be created in the Workflow tasks section of the Wagtail Admin. ## Task models -All custom tasks must be models inheriting from `wagtailcore.Task`. In this set of examples, we'll set up a task that can be approved by only one specific user. +All custom tasks must be models inheriting from `wagtailcore.Task`. + +If you need to customize the behavior of the built-in `GroupApprovalTask`, create a custom task which inherits from `AbstractGroupApprovalTask` and add your customizations there. +See below for more details on how to customize behavior. + +In this set of examples, we'll set up a task that can be approved by only one specific user. ```python # /models.py diff --git a/docs/releases/6.1.md b/docs/releases/6.1.md index b6eb836d513b..d60985e913f2 100644 --- a/docs/releases/6.1.md +++ b/docs/releases/6.1.md @@ -27,6 +27,7 @@ depth: 1 * Implement new universal listings design for image listing view (Sage Abdullah) * Implement new universal listings design for document listing view (Sage Abdullah) * Implement new universal listings design for site and locale listing views (Sage Abdullah) + * Added `AbstractGroupApprovalTask` to simplify [customizing behavior of custom `Task` models](../extending/custom_tasks) (John-Scott Atlakson) ### Bug fixes diff --git a/wagtail/models/__init__.py b/wagtail/models/__init__.py index 9609e54f30d1..88a12f721c3f 100644 --- a/wagtail/models/__init__.py +++ b/wagtail/models/__init__.py @@ -3616,7 +3616,7 @@ class Workflow(AbstractWorkflow): pass -class GroupApprovalTask(Task): +class AbstractGroupApprovalTask(Task): groups = models.ManyToManyField( Group, verbose_name=_("groups"), @@ -3698,10 +3698,15 @@ def get_description(cls): return _("Members of the chosen Wagtail Groups can approve this task") class Meta: + abstract = True verbose_name = _("Group approval task") verbose_name_plural = _("Group approval tasks") +class GroupApprovalTask(AbstractGroupApprovalTask): + pass + + class WorkflowStateQuerySet(models.QuerySet): def active(self): """