From f9adb78ae4abd135dbb11b034a43b47e51f9fa71 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Wed, 3 Feb 2016 20:21:54 +0000 Subject: [PATCH] Switch wagtaildocs to use CollectionOwnershipPermissionPolicy --- wagtail/wagtaildocs/permissions.py | 6 ++++-- wagtail/wagtaildocs/tests.py | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/wagtail/wagtaildocs/permissions.py b/wagtail/wagtaildocs/permissions.py index 3267ba79cb..112f9a644d 100644 --- a/wagtail/wagtaildocs/permissions.py +++ b/wagtail/wagtaildocs/permissions.py @@ -1,8 +1,10 @@ -from wagtail.wagtailcore.permission_policies import OwnershipPermissionPolicy +from wagtail.wagtailcore.permission_policies.collections import ( + CollectionOwnershipPermissionPolicy +) from wagtail.wagtaildocs.models import Document, get_document_model -permission_policy = OwnershipPermissionPolicy( +permission_policy = CollectionOwnershipPermissionPolicy( get_document_model(), auth_model=Document, owner_field_name='uploaded_by_user' diff --git a/wagtail/wagtaildocs/tests.py b/wagtail/wagtaildocs/tests.py index 3112b35b8e..247b9555bf 100644 --- a/wagtail/wagtaildocs/tests.py +++ b/wagtail/wagtaildocs/tests.py @@ -18,7 +18,7 @@ from django.conf import settings from django.utils.six import b from wagtail.tests.utils import WagtailTestUtils -from wagtail.wagtailcore.models import Page +from wagtail.wagtailcore.models import Page, Collection, GroupCollectionPermission from wagtail.tests.testapp.models import EventPage, EventPageRelatedLink from wagtail.wagtaildocs.models import Document @@ -72,7 +72,12 @@ class TestDocumentPermissions(TestCase): ) # Owner user must have the add_document permission - self.owner.user_permissions.add(Permission.objects.get(codename='add_document')) + self.adders_group = Group.objects.create(name='Document adders') + GroupCollectionPermission.objects.create( + group=self.adders_group, collection=Collection.get_first_root_node(), + permission=Permission.objects.get(codename='add_document') + ) + self.owner.groups.add(self.adders_group) # Create a document for running tests on self.document = models.Document.objects.create(title="Test document", uploaded_by_user=self.owner) @@ -945,7 +950,14 @@ class TestEditOnlyPermissions(TestCase, WagtailTestUtils): ) change_permission = Permission.objects.get(content_type__app_label='wagtaildocs', codename='change_document') admin_permission = Permission.objects.get(content_type__app_label='wagtailadmin', codename='access_admin') - user.user_permissions.add(change_permission, admin_permission) + self.changers_group = Group.objects.create(name='Document changers') + GroupCollectionPermission.objects.create( + group=self.changers_group, collection=Collection.get_first_root_node(), + permission=change_permission + ) + user.groups.add(self.changers_group) + + user.user_permissions.add(admin_permission) self.client.login(username='changeonly', password='password') def test_get_index(self):