kopia lustrzana https://github.com/wagtail/wagtail
Replace workflow support check with WAGTAIL_WORKFLOW_ENABLED setting check
The workflow models can always be imported via wagtail.models even if workflow is disabled. Instead of checking the import with try/except, we should check the setting instead.pull/10619/head
rodzic
690d0a740e
commit
2a888bcb30
|
@ -1,15 +1,9 @@
|
|||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.db.models import Q
|
||||
from django.utils import timezone
|
||||
|
||||
from wagtail.models import Revision
|
||||
|
||||
try:
|
||||
from wagtail.models import WorkflowState
|
||||
|
||||
workflow_support = True
|
||||
except ImportError:
|
||||
workflow_support = False
|
||||
from wagtail.models import Revision, WorkflowState
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
@ -46,7 +40,7 @@ def purge_revisions(days=None):
|
|||
approved_go_live_at__isnull=False
|
||||
)
|
||||
|
||||
if workflow_support:
|
||||
if getattr(settings, "WAGTAIL_WORKFLOW_ENABLED", True):
|
||||
purgeable_revisions = purgeable_revisions.exclude(
|
||||
# and exclude revisions linked to an in progress or needs changes workflow state
|
||||
Q(task_states__workflow_state__status=WorkflowState.STATUS_IN_PROGRESS)
|
||||
|
|
|
@ -6,11 +6,19 @@ from django.contrib.auth import get_user_model
|
|||
from django.contrib.auth.models import Group
|
||||
from django.core import management
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.test import TestCase, override_settings
|
||||
from django.utils import timezone
|
||||
|
||||
from wagtail.embeds.models import Embed
|
||||
from wagtail.models import Collection, Page, PageLogEntry, Revision
|
||||
from wagtail.models import (
|
||||
Collection,
|
||||
Page,
|
||||
PageLogEntry,
|
||||
Revision,
|
||||
Task,
|
||||
Workflow,
|
||||
WorkflowTask,
|
||||
)
|
||||
from wagtail.signals import page_published, page_unpublished, published, unpublished
|
||||
from wagtail.test.testapp.models import (
|
||||
DraftStateModel,
|
||||
|
@ -643,7 +651,7 @@ class TestPurgeRevisionsCommandForPages(TestCase):
|
|||
self.assertFalse(Revision.objects.filter(id=revision_1.id).exists())
|
||||
self.assertTrue(Revision.objects.filter(id=revision_2.id).exists())
|
||||
|
||||
def test_revisions_in_moderation_not_purged(self):
|
||||
def test_revisions_in_moderation_or_workflow_not_purged(self):
|
||||
revision = self.object.save_revision(submitted_for_moderation=True)
|
||||
|
||||
# Save a new revision to ensure that the moderated revision
|
||||
|
@ -654,28 +662,29 @@ class TestPurgeRevisionsCommandForPages(TestCase):
|
|||
|
||||
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
||||
|
||||
try:
|
||||
from wagtail.models import Task, Workflow, WorkflowTask
|
||||
workflow = Workflow.objects.create(name="test_workflow")
|
||||
task_1 = Task.objects.create(name="test_task_1")
|
||||
user = get_user_model().objects.first()
|
||||
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
|
||||
|
||||
workflow = Workflow.objects.create(name="test_workflow")
|
||||
task_1 = Task.objects.create(name="test_task_1")
|
||||
user = get_user_model().objects.first()
|
||||
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
|
||||
revision = self.object.save_revision()
|
||||
workflow.start(self.object, user)
|
||||
|
||||
revision = self.object.save_revision()
|
||||
workflow.start(self.object, user)
|
||||
# Save a new revision to ensure that the revision in the workflow
|
||||
# is not the latest one
|
||||
self.object.save_revision()
|
||||
|
||||
# Save a new revision to ensure that the revision in the workflow
|
||||
# is not the latest one
|
||||
self.object.save_revision()
|
||||
self.run_command()
|
||||
|
||||
# even though they're no longer the latest revisions, the old revisions
|
||||
# should stay as they are attached to an in progress workflow
|
||||
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
||||
|
||||
# If workflow is disabled at some point after that, the revision should
|
||||
# be deleted
|
||||
with override_settings(WAGTAIL_WORKFLOW_ENABLED=False):
|
||||
self.run_command()
|
||||
|
||||
# even though they're no longer the latest revisions, the old revisions
|
||||
# should stay as they are attached to an in progress workflow
|
||||
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
||||
except ImportError:
|
||||
pass
|
||||
self.assertFalse(Revision.objects.filter(id=revision.id).exists())
|
||||
|
||||
def test_revisions_with_approve_go_live_not_purged(self):
|
||||
revision = self.object.save_revision(
|
||||
|
|
Ładowanie…
Reference in New Issue