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.core.management.base import BaseCommand
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from wagtail.models import Revision
|
from wagtail.models import Revision, WorkflowState
|
||||||
|
|
||||||
try:
|
|
||||||
from wagtail.models import WorkflowState
|
|
||||||
|
|
||||||
workflow_support = True
|
|
||||||
except ImportError:
|
|
||||||
workflow_support = False
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -46,7 +40,7 @@ def purge_revisions(days=None):
|
||||||
approved_go_live_at__isnull=False
|
approved_go_live_at__isnull=False
|
||||||
)
|
)
|
||||||
|
|
||||||
if workflow_support:
|
if getattr(settings, "WAGTAIL_WORKFLOW_ENABLED", True):
|
||||||
purgeable_revisions = purgeable_revisions.exclude(
|
purgeable_revisions = purgeable_revisions.exclude(
|
||||||
# and exclude revisions linked to an in progress or needs changes workflow state
|
# and exclude revisions linked to an in progress or needs changes workflow state
|
||||||
Q(task_states__workflow_state__status=WorkflowState.STATUS_IN_PROGRESS)
|
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.contrib.auth.models import Group
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.test import TestCase
|
from django.test import TestCase, override_settings
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from wagtail.embeds.models import Embed
|
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.signals import page_published, page_unpublished, published, unpublished
|
||||||
from wagtail.test.testapp.models import (
|
from wagtail.test.testapp.models import (
|
||||||
DraftStateModel,
|
DraftStateModel,
|
||||||
|
@ -643,7 +651,7 @@ class TestPurgeRevisionsCommandForPages(TestCase):
|
||||||
self.assertFalse(Revision.objects.filter(id=revision_1.id).exists())
|
self.assertFalse(Revision.objects.filter(id=revision_1.id).exists())
|
||||||
self.assertTrue(Revision.objects.filter(id=revision_2.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)
|
revision = self.object.save_revision(submitted_for_moderation=True)
|
||||||
|
|
||||||
# Save a new revision to ensure that the moderated revision
|
# Save a new revision to ensure that the moderated revision
|
||||||
|
@ -654,9 +662,6 @@ class TestPurgeRevisionsCommandForPages(TestCase):
|
||||||
|
|
||||||
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
||||||
|
|
||||||
try:
|
|
||||||
from wagtail.models import Task, Workflow, WorkflowTask
|
|
||||||
|
|
||||||
workflow = Workflow.objects.create(name="test_workflow")
|
workflow = Workflow.objects.create(name="test_workflow")
|
||||||
task_1 = Task.objects.create(name="test_task_1")
|
task_1 = Task.objects.create(name="test_task_1")
|
||||||
user = get_user_model().objects.first()
|
user = get_user_model().objects.first()
|
||||||
|
@ -674,8 +679,12 @@ class TestPurgeRevisionsCommandForPages(TestCase):
|
||||||
# even though they're no longer the latest revisions, the old revisions
|
# even though they're no longer the latest revisions, the old revisions
|
||||||
# should stay as they are attached to an in progress workflow
|
# should stay as they are attached to an in progress workflow
|
||||||
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
self.assertTrue(Revision.objects.filter(id=revision.id).exists())
|
||||||
except ImportError:
|
|
||||||
pass
|
# If workflow is disabled at some point after that, the revision should
|
||||||
|
# be deleted
|
||||||
|
with override_settings(WAGTAIL_WORKFLOW_ENABLED=False):
|
||||||
|
self.run_command()
|
||||||
|
self.assertFalse(Revision.objects.filter(id=revision.id).exists())
|
||||||
|
|
||||||
def test_revisions_with_approve_go_live_not_purged(self):
|
def test_revisions_with_approve_go_live_not_purged(self):
|
||||||
revision = self.object.save_revision(
|
revision = self.object.save_revision(
|
||||||
|
|
Ładowanie…
Reference in New Issue