0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00
This commit is contained in:
jacobtoppm 2020-02-13 11:52:06 +00:00 committed by Matt Westcott
parent e393721e15
commit fe1ffe1601
3 changed files with 15 additions and 13 deletions

View File

@ -383,7 +383,7 @@ class TestSubmitToWorkflow(TestCase, WagtailTestUtils):
workflow = Workflow.objects.create(name='test_workflow')
task_1 = GroupApprovalTask.objects.create(name='test_task_1')
task_1.groups.set(Group.objects.filter(name='Moderators'))
workflow_task_1 = WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
return workflow, task_1
def submit(self):
@ -482,7 +482,7 @@ class TestApproveRejectWorkflow(TestCase, WagtailTestUtils):
workflow = Workflow.objects.create(name='test_workflow')
task_1 = GroupApprovalTask.objects.create(name='test_task_1')
task_1.groups.set(Group.objects.filter(name='Moderators'))
workflow_task_1 = WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
return workflow, task_1
def submit(self):
@ -652,7 +652,7 @@ class TestNotificationPreferences(TestCase, WagtailTestUtils):
workflow = Workflow.objects.create(name='test_workflow')
task_1 = GroupApprovalTask.objects.create(name='test_task_1')
task_1.groups.set(Group.objects.filter(name='Moderators'))
workflow_task_1 = WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
return workflow, task_1
def submit(self):
@ -856,8 +856,8 @@ class TestDisableViews(TestCase, WagtailTestUtils):
task_1.groups.set(Group.objects.filter(name='Moderators'))
task_2 = GroupApprovalTask.objects.create(name='test_task_2')
task_2.groups.set(Group.objects.filter(name='Moderators'))
workflow_task_1 = WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
workflow_task_2 = WorkflowTask.objects.create(workflow=workflow, task=task_2, sort_order=2)
WorkflowTask.objects.create(workflow=workflow, task=task_1, sort_order=1)
WorkflowTask.objects.create(workflow=workflow, task=task_2, sort_order=2)
return workflow, task_1, task_2
def submit(self):

View File

@ -2,7 +2,11 @@
from django.db import migrations
from django.db.models import Count, Q
def create_default_workflows(apps, schema_editor):
# This will recreate the existing publish-permission based moderation setup in the new workflow system, by creating new workflows
# Get models
ContentType = apps.get_model('contenttypes.ContentType')
Workflow = apps.get_model('wagtailcore.Workflow')
@ -15,19 +19,18 @@ def create_default_workflows(apps, schema_editor):
# Create content type for GroupApprovalTask model
group_approval_content_type, __ = ContentType.objects.get_or_create(
model='groupapprovaltask', app_label='wagtailcore')
model='groupapprovaltask', app_label='wagtailcore')
publish_permissions = GroupPagePermission.objects.filter(permission_type='publish')
for permission in publish_permissions:
# find groups with publish permission over this page or its ancestors (and therefore this page by descent)
page = permission.page
page = Page.objects.get(pk=page.pk)
Page.steplen = 4
ancestors = Page.objects.ancestor_of(page)
ancestor_permissions = moderator_permissions.filter(page__in=ancestors)
groups = Group.objects.filter(Q(page_permissions__in=ancestor_permissions)|Q(page_permissions__pk=permission.pk)).distinct()
ancestor_permissions = publish_permissions.filter(page__in=ancestors)
groups = Group.objects.filter(Q(page_permissions__in=ancestor_permissions) | Q(page_permissions__pk=permission.pk)).distinct()
# get a GroupApprovalTask with groups matching these publish permission groups (and no others)
task = GroupApprovalTask.objects.filter(groups__id__in=groups.all()).annotate(count=Count('groups')).filter(count=groups.count()).filter(active=True).first()
@ -35,7 +38,7 @@ def create_default_workflows(apps, schema_editor):
# if no such task exists, create it
group_names = ' '.join([group.name for group in groups])
task = GroupApprovalTask.objects.create(
name=group_names+" Approval",
name=group_names + " Approval",
content_type=group_approval_content_type,
active=True,
)
@ -45,7 +48,7 @@ def create_default_workflows(apps, schema_editor):
workflow = Workflow.objects.annotate(task_number=Count('workflow_tasks')).filter(task_number=1).filter(workflow_tasks__task=task).filter(active=True).first()
if not workflow:
workflow = Workflow.objects.create(
name=task.name+" Workflow",
name=task.name + " Workflow",
active=True
)
@ -72,4 +75,3 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(create_default_workflows, migrations.RunPython.noop),
]

View File

@ -342,7 +342,7 @@ class BasePageManager(models.Manager):
class PageManager(BasePageManager.from_queryset(PageQuerySet)):
use_in_migrations=True
use_in_migrations = True
class PageBase(models.base.ModelBase):